package fr.titionfire.ffsaf.data.repository;

import fr.titionfire.ffsaf.data.model.CheckoutModel;
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class CheckoutRepository implements PanacheRepositoryBase<CheckoutModel, Long> {

    public Uni<Long> countByLicenseId(long id) {
        return getSession()
                .chain(s -> s
                        .createNativeQuery("SELECT COUNT(*) FROM ffsaf__checkout WHERE ?1 = ANY(license_ids)", Long.class)
                        .setParameter(1, id)
                        .getSingleResult());
    }
}
