package fr.titionfire.ffsaf.rest;

import fr.titionfire.ffsaf.domain.service.MatchService;
import fr.titionfire.ffsaf.rest.data.MatchData;
import fr.titionfire.ffsaf.utils.CompetitionSystem;
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
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/match/{system}/admin")
public class MatchAdminEndpoints {

    @PathParam("system")
    private CompetitionSystem system;

    @Inject
    MatchService service;

    @Inject
    SecurityCtx securityCtx;


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

    @GET
    @Path("getAllByPoule/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<List<MatchData>> getAllByPouleAdmin(@PathParam("id") Long id) {
        return service.getAllByPouleAdmin(securityCtx, system, id);
    }

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

    @POST
    @Path("score/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<?> updateScore(@PathParam("id") Long id, List<ScoreEmbeddable> scores) {
        return service.updateScore(securityCtx, system, id, scores);
    }

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