using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Holidays.Commands.DeleteHoliday;
using Baya.Application.Features.Holidays.Commands.UpsertHoliday;
using Baya.Application.Features.Holidays.Queries.ListHolidays;
using Baya.Application.Models.Common;
using Baya.Application.Models.Holidays;
using Baya.Infrastructure.Identity.Identity.PermissionManager;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Baya.Web.Api.Controllers.V1;

[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Authorize(ConstantPolicies.DynamicPermission)]
[Display(Description = "Admin: the Iranian holiday calendar that drives payout bank-closure scheduling")]
public sealed class HolidaysController(ISender sender) : BaseController
{
    [HttpGet("[action]")]
    [ProducesOkApiResponseType<PagedResult<HolidayDto>>]
    public async Task<IActionResult> GetHolidays([FromQuery] ListHolidaysQuery query, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(query, cancellationToken));

    [HttpPost("[action]")]
    [ProducesOkApiResponseType]
    public async Task<IActionResult> UpsertHoliday(UpsertHolidayCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));

    [HttpPost("[action]")]
    [ProducesOkApiResponseType]
    public async Task<IActionResult> DeleteHoliday(DeleteHolidayCommand command, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(command, cancellationToken));
}
