using Ewide.Core.Service.Area;
using Ewide.Core.Service.Area.Dto;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ewide.Core.Controller
{
    /// <summary>
    /// 区域代码相关服务
    /// </summary>
    [ApiDescriptionSettings(Name = "AreaCode", Order = 160)]
    public class AreaCodeController : IDynamicApiController
    {
        private readonly IAreaCodeService _areaCodeService;

        public AreaCodeController(IAreaCodeService areaCodeService)
        {
            _areaCodeService = areaCodeService;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sysArea/page")]
        public async Task<dynamic> QueryAreaCodePageList([FromBody] AreaCodeInput input)
        {
            return (await _areaCodeService.QueryAreaCodePageList(input));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet("/sysArea/{code}")]
        public async Task<AreaCodeOutput> GetAreaCode([FromRoute]string code)
        {
            return (await _areaCodeService.GetAreaCode(code)).Adapt<AreaCodeOutput>();
        }
        /// <summary>
        /// 添加区域信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sysArea/add")]
        public async Task AddAreaCode(AreaCodeInput input)
        {
            await _areaCodeService.AddAreaCode(input);
        }
        /// <summary>
        /// 更新区域信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sysArea/edit")]
        public async Task UpdateAreaCode(AreaCodeInput input)
        {
            await _areaCodeService.UpdateAreaCode(input);
        }
        /// <summary>
        /// 删除区域
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("/sysArea/delete")]
        public async Task DeleteAreaCode(DeleteAreaCodeInput input)
        {
            await _areaCodeService.DeleteAreaCode(input);
        }
        /// <summary>
        /// 获取目录树
        /// </summary>
        /// <returns></returns>
        [HttpGet("/sysArea/tree")]
        public async Task<List<AreaTreeNode>> GetAreaCodeTree()
        {
            return await _areaCodeService.GetAreaCodeTree();
        }
    }
}
