using Masuit.Tools.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using PVDEMCS.Common;
using PVDEMCS.Services;
using PVDEMCS.Services.Models;
using System.Xml.Linq;

namespace PVDEMCS.Controllers
{
    /// <summary>
    /// 系统参数设置
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class SysConfigController : Controller
    {
        private ISysConfigService _sysConfigService;
        public SysConfigController(ISysConfigService sysConfigService)
        {
            this._sysConfigService = sysConfigService;
        }
        /// <summary>
        /// 获取系统参数设置分页列表
        /// </summary>
        /// <param name="configName">参数名称</param>
        /// <param name="configKey">参数键值</param>
        /// <param name="page">当前页</param>
        /// <param name="size">页大小</param>
        /// <returns></returns>
        [HttpGet]
        public Result<PagedList<SysConfig>> GetSysConfigPageList(string configName, string configKey, int page, int size = 20)
        {
            var result = this._sysConfigService.GetSysConfigPageList(configName, configKey, page, size);
            return result;
        }

        /// <summary>
        /// 获取系统参数设置列表
        /// </summary>
        /// <param name="configName">参数名称</param>
        /// <param name="configKey">参数键值</param>
        /// <returns></returns>
        [HttpGet]
        public Result<List<SysConfig>> GetSysConfigList(string configName, string configKey)
        {
            var result = this._sysConfigService.GetSysConfigList(configName, configKey);
            return result;
        }

        /// <summary>
        /// 获取获取系统参数设置明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Result<SysConfig> GetSysConfigDetailById(string id)
        {
            var result = this._sysConfigService.GetSysConfigDetailById(id);
            return result;
        }

        /// <summary>
        /// 获取获取系统参数设置明细
        /// </summary>
        /// <param name="name"></param>
        /// /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public Result<SysConfig> GetSysConfigDetailNameOrKey(string name, string key = "")
        {
            var result = this._sysConfigService.GetSysConfigDetailNameOrKey(name, key);
            return result;
        }

        /// <summary>
        /// 添加系统参数设置
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public Result AddSysConfig(SysConfig info)
        {
            var result = this._sysConfigService.AddSysConfig(info);
            return result;
        }

        /// <summary>
        /// 更新系统参数设置
        /// </summary>
        /// <param name="info"></param>
        [HttpPost]
        public Result UpdateSysConfig(SysConfig info)
        {
            var result = this._sysConfigService.UpdateSysConfig(info);
            return result;
        }

        /// <summary>
        /// 删除系统参数设置
        /// </summary>
        /// <param name="id"></param>
        [HttpPost]
        public Result DeleteSysConfig(string id)
        {
            var result = this._sysConfigService.DeleteSysConfig(id);
            return result;
        }
    }
}
