namespace Netina.Api.Controllers;

public class DistrictController : ICarterModule
{
    public void AddRoutes(IEndpointRouteBuilder app)
    {
        var group = app.NewVersionedApi("District")
            .MapGroup("api/district");

        group.MapGet("city", GetCitiesAsync)
            .WithDisplayName("Get Cities")
            .HasApiVersion(1.0);
        group.MapGet("province", GetProvincesAsync)
            .WithDisplayName("Get Cities")
            .HasApiVersion(1.0);
    }

    private async Task<IResult> GetCitiesAsync([FromServices]IDistrictService districtService, [FromQuery] int? provinceId = null, CancellationToken cancellationToken = default)
        => TypedResults.Ok(districtService.GetCitiesAsync(provinceId));

    private async Task<IResult> GetProvincesAsync([FromServices] IDistrictService districtService, CancellationToken cancellationToken = default)
        => TypedResults.Ok(districtService.GetProvincesAsync());
}