using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.Db.AuthDb;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.User;
using WCS.Model.WebSocketModel;

namespace WCS.BLL.Services.Service
{
    public class WarningService : IWarningService
    {
        public async Task<ResponseCommon<object>> SolveWarning(SolveWarningRequest request)
        {
            //获取对应的报警
            var warning = WarningManager.Warnings
                                        .Where(t => t.Guid == request.Guid)
                                        .FirstOrDefault();
            if (warning != null)
            {
                warning.SolvedUser = request.UserName;
                WarningManager.ClearWarning(warning, request.SolveType);
            }
            //判断一下是否还存在对应报警
            warning = WarningManager.Warnings
                            .Where(t => t.Guid == request.Guid)
                            .FirstOrDefault();
            if (warning == null)
                return new ResponseCommon<object>()
                {
                    Code = 200,
                    Message = "报警解除成功！"
                };
            else
            {
                return new ResponseCommon<object>()
                {
                    Code = 201,
                    Message = "报警解除失败！请重试！"
                };
            }
        }
    }
}
