using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nirvana.Common;
using Nirvana.Common.ApiBase;
using System.Collections.Generic;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.Application.DeviceInfo
{
    /// <summary>
    /// 设备管理
    /// </summary>
    [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
    public class DeviceAppService : IDynamicApiController
    {
        private readonly IDeviceService _Service;
        public DeviceAppService(IDeviceService Service)
        {
            _Service = Service;
        }
        /// <summary>
        /// 查询设备分配记录
        /// </summary>
        /// <param name="id">设备ID</param>
        /// <returns></returns>
        [QueryParameters]
        public async Task<List<DeviceAllocListSCDto>> GetDeviceAllocListAsync(int id)
        {
            return await _Service.GetDeviceAllocListAsync(id);
        }
        /// <summary>
        /// 设备批量操作
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> BatchSetAsync(DeviceBatchModel data)
        {
            return await _Service.BatchSetAsync(data);
        }

        /// <summary>
        /// 设备列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetListAsync(QueryParams param)
        {
            var result = await _Service.GetListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }

        /// <summary>
        /// 设备类型列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetTypeListAsync(QueryParams param)
        {
            var result = await _Service.GetTypeListAsync(param);
            return new ResultInfo(ResultState.SUCCESS, "success", result);
        }

        /// <summary>
        /// 信息编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitAsync(YB_Device model)
        {
            return await _Service.SubmitAsync(model);
        }
        /// <summary>
        /// 信息编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ResultInfo> SubmitTypeAsync(YB_DeviceType model)
        {
            return await _Service.SubmitTypeAsync(model);
        }
        /// <summary>
        /// 设备停用/启用
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status">0-停用,1-启用</param>
        /// <returns></returns>
        [HttpGet]
        [QueryParameters]
        public async Task<ResultInfo> StopDevAsync(int id, DeviceStatus status)
        {
            return await _Service.StopDevAsync(id, status);
        }

        /// <summary>
        /// 设备类型关联的小程序列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> GetDeviceAppListAsync(QueryParams param)
        {
            return await _Service.GetDeviceAppListAsync(param);
        }
        /// <summary>
        /// 设备类型关联的小程序提交
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> SubmitDeviceAppAsync(DeviceAppC2SDto data)
        {
            return await _Service.SubmitDeviceAppAsync(data);
        }
        /// <summary>
        /// 设备类型关联的小程序删除
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfo> DeleteDeviceAppAsync(DeviceAppDeleteC2SDto data)
        {
            return await _Service.DeleteDeviceAppAsync(data);
        }
    }
}
