package fr.titionfire.ffsaf.rest;

import fr.titionfire.ffsaf.domain.service.CategoryService;
import fr.titionfire.ffsaf.rest.data.CategoryData;
import fr.titionfire.ffsaf.rest.data.CategoryFullData;
import fr.titionfire.ffsaf.utils.CompetitionSystem;
import fr.titionfire.ffsaf.utils.SecurityCtx;
import io.quarkus.security.Authenticated;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;

import java.util.List;

@Authenticated
@Path("api/poule/{system}/admin/")
public class CategoryAdminEndpoints {

    @PathParam("system")
    private CompetitionSystem system;

    @Inject
    CategoryService service;

    @Inject
    SecurityCtx securityCtx;


    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<CategoryData> getByIdAdmin(@PathParam("id") Long id) {
        return service.getByIdAdmin(securityCtx, system, id);
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<List<CategoryData>> getAllAdmin() {
        return service.getAllAdmin(securityCtx, system);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<CategoryData> addOrUpdate(CategoryData data) {
        return service.addOrUpdate(securityCtx, system, data);
    }

    @POST
    @Path("sync")
    @Consumes(MediaType.APPLICATION_JSON)
    public Uni<?> syncCategory(CategoryFullData data) {
        return service.syncCategory(securityCtx, system, data);
    }

    @DELETE
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<?> delete(@PathParam("id") Long id) {
        return service.delete(securityCtx, system, id);
    }
}
