package fr.titionfire.ffsaf.data.repository;

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

@ApplicationScoped
public class CategoryRepository implements PanacheRepositoryBase<CategoryModel, Long> {

    public Uni<CategoryModel> create(CategoryModel categoryModel) {
        categoryModel.setSystem(CompetitionSystem.INTERNAL);
        return Panache.withTransaction(() -> this.persist(categoryModel)
                .invoke(categoryModel1 -> categoryModel1.setSystemId(categoryModel1.getId())))
                .chain(this::persist);
    }
}
