using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp.BiddingAgencyManager.Request;
using OpenAuth.App.ServiceApp.BiddingAgencyManager;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers.ServiceController
{    /// <summary>
     /// 代理商信息
     /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BiddingAgencyController
    {
        private readonly BiddingAgencyApp _app;
        public BiddingAgencyController(BiddingAgencyApp app)
        {
            _app = app;
        }

        /// <summary>
        /// 查询代理商信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<PpBiddingagency>>>> LoadBiddingAgency([FromQuery] BiddingAgencyReq req)
        {
            var result = new Response<PageInfo<List<PpBiddingagency>>>();
            try
            {
                result = await _app.LoadBiddingAgency(req);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据id查询单个代理商信息--编辑代理商信息用
        /// </summary>
        /// <param name="id">代理商信息id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PpBiddingagency>> LoadBiddingAgencyById(string id)
        {
            var result = new Response<PpBiddingagency>();
            try
            {
                result = await _app.LoadBiddingAgencyById(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }


        /// <summary>
        /// 添加代理商信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddBiddingAgency(PpBiddingagency info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.AddBiddingAgency(info);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 编辑代理商信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> EditBiddingAgency(PpBiddingagency info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.EditBiddingAgency(info);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 删除代理商信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeleteBiddingAgency(string id)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.DeleteBiddingAgency(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }


        /// <summary>
        /// 审核代理商信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> ReviewBiddingAgency(string id)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.ReviewBiddingAgency(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }


        /// <summary>
        /// 为代理商分配账号信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddCompanyAccount(List<PpAgencyaccount> info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.AddCompanyAccount(info);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据代理商id查询分配的账号信息--编辑代理商账号分配时使用
        /// </summary>
        /// <param name="id">代理商id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<string>> LoadBidAgencyUserInfoById(string id)
        {
            var result = new Response<string>();
            try
            {
                result = await _app.LoadBidAgencyUserInfoById(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 根据当前登录用户查询理商信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<PpBiddingagency>>>> LoadBiddingAgencyByUser()
        {
            var result = new Response<PageInfo<List<PpBiddingagency>>>();
            try
            {
                result = await _app.LoadBiddingAgencyByUser();
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }

    }
}
