using System.ComponentModel.DataAnnotations;
using Asp.Versioning;
using Baya.Application.Features.Catalog.Queries.GetCatalogCategories;
using Baya.Application.Features.Catalog.Queries.GetCategoryOptionGroups;
using Baya.Application.Models.Catalog;
using Baya.Application.Models.Common;
using Baya.WebFramework.Attributes;
using Baya.WebFramework.BaseController;
using Mediator;
using Microsoft.AspNetCore.Mvc;

namespace Baya.Web.Api.Controllers.V1;

[ApiVersion("1")]
[ApiController]
[Route("api/v{version:apiVersion}/[controller]")]
[Display(Description = "Public catalog browse: active categories and a category's applicable option groups")]
public sealed class CatalogController(ISender sender) : BaseController
{
    [HttpGet("[action]")]
    [ProducesOkApiResponseType<PagedResult<ServiceCategoryDto>>]
    public async Task<IActionResult> Categories([FromQuery] GetCatalogCategoriesQuery query, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(query, cancellationToken));

    [HttpGet("[action]")]
    [ProducesOkApiResponseType<IReadOnlyList<OptionGroupDto>>]
    public async Task<IActionResult> OptionGroups([FromQuery(Name = "category_id")] long categoryId, CancellationToken cancellationToken)
        => OperationResult(await sender.Send(new GetCategoryOptionGroupsQuery(categoryId), cancellationToken));
}
