using Masuit.Tools;
using Masuit.Tools.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using PVDEMCS.Common;
using PVDEMCS.Common.Constant;
using PVDEMCS.Devices;
using PVDEMCS.Services;
using PVDEMCS.Services.Impl;
using PVDEMCS.Services.Models;
using System;

namespace PVDEMCS.Controllers
{
    /// <summary>
    /// 设备管理
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class EquipmentController : Controller
    {
        private IEquipmentService _equipmentService;
        private IDeviceRun _deviceRun;

        public EquipmentController(IEquipmentService equipmentService, IDeviceRun deviceRun)
        {
            this._equipmentService = equipmentService;
            _deviceRun = deviceRun;
        }
        /// <summary>
        /// 获取设备分页列表
        /// </summary>
        /// <param name="equipmentName">设备名称</param>
        /// <param name="equipmentCode">设备编号</param>
        /// <param name="equipmentType">设备类型</param>
        /// <param name="activated">是否启用</param>
        /// <param name="page">当前页</param>
        /// <param name="size">页大小</param>
        /// <returns></returns>
        [HttpGet]
        public Result<PagedList<EquipmentInfo>> GetEquipmentPageList(string equipmentName, string equipmentCode, string equipmentType, bool? activated, int page, int size = 20)
        {
            var result = this._equipmentService.GetEquipmentPageList(equipmentName, equipmentCode, equipmentType, activated, page, size);

            return result;
        }

        /// <summary>
        /// 获取设备列表
        /// </summary>
        /// <param name="equipmentName">设备名称</param>
        /// <param name="equipmentCode">设备编号</param>
        /// <param name="activated">是否启用</param>
        [HttpGet]
        public Result<List<EquipmentInfo>> GetEquipmentList(string equipmentName, string equipmentCode, string equipmentType, bool? activated)
        {
            var result = this._equipmentService.GetEquipmentList(equipmentName, equipmentCode, equipmentType, activated);

            return result;
        }


        /// <summary>
        /// 获取设备明显
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Result<EquipmentInfo> GetEquipmentDetail(string id)
        {
            var result = this._equipmentService.GetEquipmentDetail(id);
            return result;
        }

        /// <summary>
        /// 添加设备信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public Result AddEquipment(EquipmentInfo info)
        {
            var result = this._equipmentService.AddEquipment(info);
            _deviceRun.Run();
            return result;
        }

        /// <summary>
        /// 更新设备信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public Result UpdateEquipment(EquipmentInfo info)
        {
            var result = this._equipmentService.UpdateEquipment(info);
            _deviceRun.Run();
            return result;
        }

        /// <summary>
        /// 删除设备信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Result DeleteEquipment(string id)
        {
            var result = this._equipmentService.DeleteEquipment(id);
            _deviceRun.Run();
            return result;
        }
    }
}
