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

namespace OpenAuth.WebApi.Controllers.ServiceController
{
    /// <summary>
    /// 招标企业
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PpBiddingcompanyController : ControllerBase
    {
        private readonly PpBiddingcompanyApp _app;
        public PpBiddingcompanyController(PpBiddingcompanyApp app)
        {
            _app = app;
        }

        /// <summary>
        /// 查询招标企业
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<PpBiddingcompany>>>> LoadBiddingCompanyInfo([FromQuery] BiddingCompanyInfoReq req)
        {
            var result = new Response<PageInfo<List<PpBiddingcompany>>>();
            try
            {
                result = await _app.LoadBiddingCompanyInfo(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<PpBiddingcompany>> LoadBiddingCompanyInfoById(string id)
        {
            var result = new Response<PpBiddingcompany>();
            try
            {
                result = await _app.LoadBiddingCompanyInfoById(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>> AddBiddingCompanyInfo(PpBiddingcompany info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.AddBiddingCompanyInfo(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>> EditBiddingCompanyInfo(PpBiddingcompany info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.EditBiddingCompanyInfo(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>> DeleteBiddingCompanyInfo(string id)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.DeleteBiddingCompanyInfo(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<PpCompanyaccount> 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>> LoadBidUserInfoById(string id)
        {
            var result = new Response<string>();
            try
            {
                result = await _app.LoadBidUserInfoById(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<PpBiddingcompany>>>> LoadCompanyInfoByUser()
        {
            var result = new Response<PageInfo<List<PpBiddingcompany>>>();
            try
            {
                result = await _app.LoadCompanyInfoByUser();
            }
            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>> AllocateSupplier(List<PpBiddingsupplier> info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.AllocateSupplier(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>> AllocateAgency(List<PpBidagencycompany> info)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.AllocateAgency(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<List<string>>> LoadBidAgencyById(string id)
        {
            var result = new Response<List<string>>();
            try
            {
                result = await _app.LoadBidAgencyById(id);
            }
            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<List<string>>> LoadBidcompanyById(string id)
        {
            var result = new Response<List<string>>();
            try
            {
                result = await _app.LoadBidcompanyById(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return result;
        }
    }

}
