using Microsoft.AspNetCore.Authorization;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MTWorkHR.Application.Filters;
using MTWorkHR.Application.Identity;
using MTWorkHR.Application.Models;
using MTWorkHR.Application.Services;
using MTWorkHR.Application.Services.Interfaces;

namespace MTWorkHR.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [AppAuthorize]
    public class CompanyController : ControllerBase
    {
        private readonly ICompanyService _companyService;
        public CompanyController(ICompanyService CompanyService) 
        {
            this._companyService = CompanyService;
        }
        [HttpGet("GetAll")]
        [Authorize(Policy = "SuperAdminOnly")]
        [AppAuthorize(Permissions = "Company")]
        public async Task<ActionResult<List<CompanyDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
        {
            return Ok( await _companyService.GetAll(pagingInput));
        }
        [HttpGet("Get")]
        [AppAuthorize(Permissions = "Company")]
        public async Task<ActionResult<UpdateCompanyDto>> Get()
        {
            return Ok(await _companyService.GetById());
        }
        [HttpGet("GetById")]
        [AppAuthorize(Permissions = "Company")]
        public async Task<ActionResult<UpdateCompanyDto>> GetById(long companyId)
        {
            return Ok(await _companyService.GetByIdForUpdate(companyId));
        }

        [HttpPost("Create")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [Consumes("multipart/form-data")]
        [AllowAnonymous]
        [AppAuthorize(Permissions = "Company.Create")]
        public async Task<ActionResult<CompanyDto>> Create([FromForm] CompanyDto input)
        {
            return await _companyService.Create(input);
        }

        [HttpPost("Update")]
        [ProducesResponseType(StatusCodes.Status200OK)]
       // [Consumes("multipart/form-data")]
        [AppAuthorize(Permissions = "Company.Update")]
        public async Task<ActionResult<UpdateCompanyDto>> Update([FromBody] UpdateCompanyDto input)
        {
            return await _companyService.Update(input);
        }
        
        [HttpDelete("Delete")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        // [AppAuthorize(Permissions = "Company.Delete")]
        [Authorize(Policy = "SuperAdminOnly")]
        [AppAuthorize(Permissions = "Company.Delete")]
        public async Task Delete([FromQuery] long id)
        {
            await _companyService.Delete(id);
        }

        [HttpDelete("Suspend")]
        [ProducesResponseType(StatusCodes.Status200OK)]
        //[AppAuthorize(Permissions = "Company.Suspend")]
        [Authorize(Policy = "SuperAdminOnly")]
        [AppAuthorize(Permissions = "Company.Suspend")]
        public async Task Suspend([FromQuery] long id)
        {
            await _companyService.Suspend(id);
        }


    }
}
