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

namespace OpenAuth.WebApi.Controllers.ServiceController
{
    /// <summary>
    /// 土地/房屋贡献
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TaxGongxianController : ControllerBase
    {
        TaxGongxianApp _comApp;
        public TaxGongxianController(
            TaxGongxianApp comApp)
        {
            _comApp = comApp;
        }

        #region 土地贡献
        #region 获取分页数据列表
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<TaxGongxiandi>>>> LoadGongxiandiPageList(string sszdbm, int page, int limit)
        {
            var result = new Response<PageInfo<List<TaxGongxiandi>>>();
            try
            {
                var data = await _comApp.LoadGongxiandiPageList(sszdbm, page, limit);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据id获取单个土地贡献
        /// </summary>
        /// <param name="gid">企业土地贡献gid</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<TaxGongxiandi>> GetGongxiandiInfoById(string id)
        {
            var result = new Response<TaxGongxiandi>();
            try
            {
                var data = await _comApp.GetGongxiandiInfoById(id);
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据所属宗地编码获取土地贡献
        /// </summary>
        /// <param name="sszdbm">所属宗地编码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TaxGongxiandi>>> GetGongxiandiInfoByBM(string sszdbm)
        {
            var result = new Response<List<TaxGongxiandi>>();
            try
            {
                var data = await _comApp.GetGongxiandiInfoByBM(sszdbm);
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion
        #region
        /// <summary>
        /// 添加土地贡献
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        public async Task<Response<bool>> AddGongxiandi(TaxGongxiandi req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.AddGongxiandi(req);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 编辑土地贡献
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        public async Task<Response<bool>> UpdateGongxiandi(TaxGongxiandi req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.UpdateGongxiandi(req);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 删除土地贡献
        /// </summary>
        /// <param name="ids">企业土地贡献gid</param>
        [HttpPost]
        public async Task<Response<bool>> DeleteGongxiandi(string[] ids)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.DeleteGongxiandi(ids);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion
        #endregion

        #region 房屋贡献
        #region 获取分页数据列表
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<TaxGongxianfang>>>> LoadGongxianfangPageList(string sszdbm, int page, int limit)
        {
            var result = new Response<PageInfo<List<TaxGongxianfang>>>();
            try
            {
                var data = await _comApp.LoadGongxianfangPageList(sszdbm, page, limit);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据id获取单个房屋贡献
        /// </summary>
        /// <param name="gid">企业房屋贡献gid</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<TaxGongxianfang>> GetGongxianfangInfoById(string id)
        {
            var result = new Response<TaxGongxianfang>();
            try
            {
                var data = await _comApp.GetGongxianfangInfoById(id);
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据建筑物编码获取房屋贡献
        /// </summary>
        /// <param name="zzwbm">建筑物编码</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<TaxGongxianfang>>> GetGongxianfangInfoByBM(string zzwbm)
        {
            var result = new Response<List<TaxGongxianfang>>();
            try
            {
                var data = await _comApp.GetGongxianfangInfoByBM(zzwbm);
                result.Result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion
        #region
        /// <summary>
        /// 添加房屋贡献
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        public async Task<Response<bool>> AddGongxianfang(TaxGongxianfang req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.AddGongxianfang(req);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 编辑房屋贡献
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        public async Task<Response<bool>> UpdateGongxianfang(TaxGongxianfang req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.UpdateGongxianfang(req);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 删除房屋贡献
        /// </summary>
        /// <param name="ids">企业房屋贡献gid</param>
        [HttpPost]
        public async Task<Response<bool>> DeleteGongxianfang(string[] ids)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.DeleteGongxianfang(ids);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion
        #endregion
    }
}
