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.Repository.Domain;

namespace OpenAuth.WebApi.Controllers
{

    /// <summary>
    /// 现场照片
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MiScenePhotoController : ControllerBase
    {
        private readonly MiScenePhotoApp _app;
        public MiScenePhotoController(MiScenePhotoApp app)
        {
            _app = app;
        }

        #region 查询

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

        #endregion

        #region 实体
        /// <summary>
        /// 实体
        /// </summary>
        [HttpGet]
        public async Task<Response<MiScenePhoto>> Get(object id)
        {
            var result = new Response<MiScenePhoto>();
            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(MiScenePhoto 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(MiScenePhoto 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<MiScenePhoto> models)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Delete(models);

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

            return result;
        }
        #endregion
        #endregion
    }
}