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 IdleHouseController : ControllerBase
    {
        private readonly IdleHouseApp _app;
        public IdleHouseController(IdleHouseApp app)
        {
            _app = app;
        }

        #region 查询

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


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

            return result;
        }
        #endregion

        #endregion

    }
}