using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.App.ServiceApp.MiManager.Request;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers
{
    /// <summary>
    /// 提车信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MiVehiclePickupController : ControllerBase
    {
        private readonly MiVehiclePickupApp _app;
        public MiVehiclePickupController(MiVehiclePickupApp app)
        {
            _app = app;
        }

        #region 查询

        #region 分页
        /// <summary>
        /// 分页
        /// </summary>
        [HttpGet]
        public async Task<Response<PageInfo<List<dynamic>>>> LoadAllPage([FromQuery] MiVehiclePickUpreq request)
        {
            return await _app.LoadAllPage(request);
        }

        /// <summary>
        /// app扫码查询当前停车场提车信息
        /// </summary>
        /// <param name="parkingid">停车场id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<dynamic>>> Loadpickupinfo(string parkingid)
        {
            return await _app.Loadpickupinfo(parkingid);
        }

        #endregion

        #region 实体
        /// <summary>
        /// 实体
        /// </summary>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<dynamic>> Get(string  id)
        {
            var result = new Response<dynamic>();
            try
            {
                result.Result =await _app.Get(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion
        #endregion

        #region 增删改

        #region 添加


        /// <summary>
        /// 添加
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> Add(MiVehiclePickup model)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Add(model);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion

        #region 修改
        /// <summary>
        /// 修改
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> Update(MiVehiclePickup model)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Update(model);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> Delete([FromBody] List<string> ids)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Delete(ids);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion
        #region 提车审核
        /// <summary>
        /// 提车审核
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> PickUpAudit(PickUpAuditReq model)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.PickUpAudit(model);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }

        /// <summary>
        /// 提车确认
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> PickUpCar(PickupCar model)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.PickUpCar(model);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion

        /// <summary>
        /// 提车时查询所有车辆信息（未提取的）
        /// </summary>
        /// <param name="violatid">违法上报id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<dynamic>> Loadvechileinfo(string violatid)
        {
            var result = new Response<dynamic>();
            try
            {
                result.Result = await _app.Loadvechileinfo(violatid);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }

        #region  查询解除扣押单信息
        /// <summary>
        /// 根据id查询解除扣押单信息
        /// </summary>
        /// <param name="pickupid">提车信息id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<dynamic>> GetReleaseDocument(string pickupid)
        {
            var result = new Response<dynamic>();
            try
            {
                result.Result = await _app.GetReleaseDocument(pickupid);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }

        /// <summary>
        /// 根据违法上报id查询解除扣押单信息
        /// </summary>
        /// <param name="reportid">违法上报id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<dynamic>> GetReleaseDocumentByReportId(string reportid)
        {
            var result = new Response<dynamic>();
            try
            {
                result.Result = await _app.GetReleaseDocumentByReportId(reportid);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion
        #endregion
    }
}