namespace Brizco.Api.Controllers;
public class ShiftController : ICarterModule
{
    public ShiftController() 
    {
    }
    public virtual void AddRoutes(IEndpointRouteBuilder app)
    {
        var group = app.NewVersionedApi("Shift")
            .MapGroup($"api/shift")
            .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser());

        group.MapGet("", GetAllAsync)
            .WithDisplayName("GetAllShift")
            .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShifts, ApplicationPermission.ViewShifts))
            .HasApiVersion(1.0);

        group.MapGet("{id}", GetAsync)
            .WithDisplayName("GetOneShift")
            .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShifts, ApplicationPermission.ViewShifts))
            .HasApiVersion(1.0);

        group.MapPost("", Post)
            .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShifts))
            .HasApiVersion(1.0);

        group.MapPut("", Put)
            .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShifts))
            .HasApiVersion(1.0);

        group.MapDelete("{id}", Delete)
            .RequireAuthorization(builder => builder.RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageShifts))
            .HasApiVersion(1.0);
    }

    // GET:Get All Entity
    public async Task<IResult> GetAllAsync([FromQuery] int page,ISender sender, CancellationToken cancellationToken, [FromQuery] long? selectedDate)
        => TypedResults.Ok(await sender.Send(new GetShiftsQuery(Page: page, SelectedDate: selectedDate ?? 0), cancellationToken));

    // GET:Get An Entity By Id
    public async Task<IResult> GetAsync(Guid id, ISender sender, CancellationToken cancellationToken)
        => TypedResults.Ok(await sender.Send(new GetShiftQuery(id)));

    // POST:Create Entity
    public async Task<IResult> Post([FromBody] CreateShiftCommand ent, ISender mediator, CancellationToken cancellationToken)
        => TypedResults.Ok(await mediator.Send(ent, cancellationToken));

    // PUT:Update Entity
    public async Task<IResult> Put([FromBody] UpdateShiftCommand ent, ISender mediator, CancellationToken cancellationToken)
        => TypedResults.Ok(await mediator.Send(ent, cancellationToken));

    // DELETE:Delete Entity
    public async Task<IResult> Delete(Guid id, ISender mediator, CancellationToken cancellationToken)
        => TypedResults.Ok(await mediator.Send(new DeleteShiftCommand(id), cancellationToken));

}

