using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.ServiceApp.TaxManage;
using OpenAuth.App.ServiceApp.TaxManage.Response;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers
{
    /// <summary>
    /// 地图
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TaxManagementController : ControllerBase
    {
        TaxManagementApp _taxApp;
        SysDataItemApp dataItemApp;
        public TaxManagementController(
            TaxManagementApp taxApp, SysDataItemApp dataItemApp)
        {
            _taxApp = taxApp;
            this.dataItemApp = dataItemApp;
        }

        #region 税源地图页面所需接口
        /// <summary>
        /// 查询图层
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TaxTuceng>>> GetTucengInfo()
        {
            var result = new Response<List<TaxTuceng>>();
            try
            {
                var data = await _taxApp.GetTucengInfo();
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 房屋图层查询
        /// </summary>
        /// <param name="name">宗地编码或者企业名称</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<dynamic>>> GetTaxBuildingInfo(string name)
        {
            var result = new Response<List<dynamic>>();
            try
            {
                var data = await _taxApp.GetTaxBuildingInfo(name);
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 宗地图层查询
        /// </summary>
        /// <param name="name">宗地编码或者企业名称</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<dynamic>>> GetTaxZongdiInfo(string name)
        {
            var result = new Response<List<dynamic>>();
            try
            {
                var data = await _taxApp.GetTaxZongdiInfo(name);
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion

        #region 地图图表数据
        /// <summary>
        /// 获取地图统计数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<dynamic>> LoadMapTotalData()
        {
            var result = new Response<dynamic>();
            try
            {
                var data = await _taxApp.LoadMapTotalData();
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        /// <summary>
        /// 获取图表数据（房产面积，土地面积）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TaxResponse>>> LoadChartData()
        {
            var result = new Response<List<TaxResponse>>();
            try
            {
                var data = await _taxApp.LoadChartData();
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 获取图表数据（房产贡献，土地贡献）
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TaxgongxianResponse>>> LoadgongxianChartData()
        {
            var result = new Response<List<TaxgongxianResponse>>();
            try
            {
                var data = await _taxApp.LoadgongxianChartData();
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion
    }
}
