using SafeCampus.Application.Services.Business.CameraInfoService;
using System.Collections.Generic;

namespace SafeCampus.Web.Core.Controllers.Application.Business;
/// <summary>
/// 摄像头管理接口
/// </summary>
[ApiDescriptionSettings(ApiGroupConsts.SYSTEM_Business, Order = 91, Tag = "摄像头管理")]
[Route("/business/cameraInfo")]
[RolePermission]
public class CameraInfoController
{
    private readonly ICameraInfoService _cameraInfoService;

    public CameraInfoController(ICameraInfoService cameraInfoService)
    {
        _cameraInfoService = cameraInfoService;
    }

    /// <summary>
    /// 数据同步
    /// </summary>
    /// <returns></returns>
    public async Task<bool> DataSync()
    {
        return await _cameraInfoService.DataSync();
    }
    /// <summary>
    /// 获取摄像头列表
    /// </summary>
    /// <param name="search"></param>
    /// <returns></returns>
    public async Task<SqlSugarPagedList<CameraInfoDto>> GetPageList(CameraSearch search)
    {
        return await _cameraInfoService.GetPageList(search);
    }
    /// <summary>
    /// 批量给摄像头设置分组
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
   public async Task<bool> BatchSetGroup(SetGroupInput input)
    {
        return await _cameraInfoService.BatchSetGroup(input);
    }
    /// <summary>
    /// 根据分组批量设置推送人
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<bool> BatchSetPushPersonByGroup(SetPushPersonGroupInput input)
    {
        return await _cameraInfoService.BatchSetPushPersonByGroup(input);
    }
    /// <summary>
    /// 对摄像头批量设置推送人
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<bool> BatchSetPushPerson(SetPushPersonInput input)
    {
        return await _cameraInfoService.BatchSetPushPerson(input);
    }
    /// <summary>
    /// 根据预警分组设置推送人
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<bool> BatchSetPushPersonByWarn(SetPushPersonWarnInput input)
    {
        return await _cameraInfoService.BatchSetPushPersonByWarn(input);
    }
    /// <summary>
    /// 设备状态统计API
    /// </summary>
    /// <returns></returns>
    public async Task<dynamic> GetCameraStatistic()
    {
        var list = await _cameraInfoService.GetPageList(new CameraSearch{PageNum = 1,PageSize = 1000});
        var numbers = new Dictionary<bool, string> { {true, "在线" }, { false, "离线" } };
        var statistics = numbers.Select(x => new
        {
            Name = x.Value,
            Count = list.List.Count(xx => xx.DeviceStatus)
        }).ToList();
        return statistics;
    }
}