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

namespace OpenAuth.WebApi.Controllers.ServiceController
{
    /// <summary>
    /// 用地线用地点
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TaxYongdixianController : ControllerBase
    {
        TaxYongdixianApp _comApp;
        public TaxYongdixianController(
            TaxYongdixianApp comApp)
        {
            _comApp = comApp;
        }

        #region 用地线
        #region 获取分页数据列表
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<TaxYongdixian>>>> LoadYongdixianPageList(string sszdbm, int page, int limit)
        {
            var result = new Response<PageInfo<List<TaxYongdixian>>>();
            try
            {
                var data = await _comApp.LoadYongdixianPageList(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<TaxYongdixian>> GetYongdixianInfoById(int gid)
        {
            var result = new Response<TaxYongdixian>();
            try
            {
                var data = await _comApp.GetYongdixianInfoById(gid);
                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<TaxYongdixian>>> GetYongdixianInfoByBM(string sszdbm)
        {
            var result = new Response<List<TaxYongdixian>>();
            try
            {
                var data = await _comApp.GetYongdixianInfoByBM(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>> AddYongdixian(TaxYongdixian req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.AddYongdixian(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>> UpdateYongdixian(TaxYongdixian req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.UpdateYongdixian(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>> DeleteYongdixian(int[] ids)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.DeleteYongdixian(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<TaxYongdidian>>>> LoadYongdidianPageList(string sszdbm, int page, int limit)
        {
            var result = new Response<PageInfo<List<TaxYongdidian>>>();
            try
            {
                var data = await _comApp.LoadYongdidianPageList(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<TaxYongdidian>> GetYongdidianInfoById(int gid)
        {
            var result = new Response<TaxYongdidian>();
            try
            {
                var data = await _comApp.GetYongdidianInfoById(gid);
                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<TaxYongdidian>>> GetYongdidianInfoByBM(string sszdbm)
        {
            var result = new Response<List<TaxYongdidian>>();
            try
            {
                var data = await _comApp.GetYongdidianInfoByBM(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>> AddYongdidian(TaxYongdidian req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.AddYongdidian(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>> UpdateYongdidian(TaxYongdidian req)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.UpdateYongdidian(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>> DeleteYongdidian(int[] ids)
        {
            var result = new Response<bool>();
            try
            {
                var data = await _comApp.DeleteYongdidian(ids);
                result = data;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
        #endregion
        #endregion
    }
}
