using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.Request;
using OpenAuth.App;
using Infrastructure;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers
{
    /// <summary>
    /// 土地
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class IdleLandController : ControllerBase
    {
        private IdleLandApp app;
        public IdleLandController(IdleLandApp _app)
        {
            app = _app;
        }

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


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<IdleLand>> Detail(string id)
        {
            var result = new Response<IdleLand>();
            try
            {
                result.Result = await app.Detail(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion

        /// <summary>
        /// 查图层
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public IActionResult QueryVectorTileByTable([FromQuery] QueryVectorTileByTableReq req)
        {
            var model = req.MapTo<VectorTileSearchModel>();

            var result = app.VectorTile(model);
            return File(result, "application/octet-stream");
        }
    }
}
