using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aurora.Tenant.IService;
using Aurora.Tenant.IService.Dto;
using Aurora.Infrastructure.Response;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace Aurora.Tenant.Api.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class TenantController : ControllerBase
    {
        private readonly ILogger<TenantController> _logger;
        private readonly ITenantService _tenantService;

        public TenantController(ILogger<TenantController> logger,
        ITenantService TenantService)
        {
            _logger = logger;
            _tenantService = TenantService;
        }

        [HttpGet]
        /// <summary>
        /// get tenants list
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> GetList()
        {
            var res = await _tenantService.GetList();
            return Ok(res);
        }

        [HttpGet]
        /// <summary>
        /// get tenant by id
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseModel<TenantUserDto>> GetById(int id)
        {
            var res = await _tenantService.GetById(id);
            return res;
        }
     
        [HttpGet]
        /// <summary>
        /// get tenant by current request url
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseModel<TenantUserDto>> GetByUrl(string url)
        {
            var res = await _tenantService.GetById(id);
            return res;
        }

        [HttpPost]
        /// <summary>
        /// add tenant
        /// </summary>
        /// <returns></returns>
        public async Task<ResponseModel<TenantUserDto>> Add(TenantUserDto model)
        {
            var res = await _tenantService.Add(model);
            return res;
        }
    }
}
