package fr.titionfire.ffsaf.rest.data;

import fr.titionfire.ffsaf.data.model.*;
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
import fr.titionfire.ffsaf.utils.Categorie;
import fr.titionfire.ffsaf.utils.Genre;
import fr.titionfire.ffsaf.utils.Utils;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@RegisterForReflection
public class SimpleRegisterComb {
    private long id;
    private String fname;
    private String lname;
    private Genre genre;
    private String country;
    private Categorie categorie;
    private SimpleClubModel club;
    private Integer licence;
    private Float weight;
    private Float weightReal;
    private int overCategory;
    private boolean hasLicenceActive;
    private boolean lockEdit;
    private List<Long> categoriesInscrites;

    public static SimpleRegisterComb fromModel(RegisterModel register, List<LicenceModel> licences) {
        MembreModel membreModel = register.getMembre();
        return new SimpleRegisterComb(membreModel.getId(), membreModel.getFname(), membreModel.getLname(),
                membreModel.getGenre(), membreModel.getCountry(),
                (register.getCategorie() == null) ? null : register.getCategorie(),
                SimpleClubModel.fromModel(register.getClub()), membreModel.getLicence(), register.getWeight(),
                register.getWeightReal(), register.getOverCategory(),
                licences.stream().anyMatch(l -> l.isValidate() && l.getSaison() == Utils.getSaison()),
                register.isLockEdit(), new ArrayList<>());
    }

    public static SimpleRegisterComb fromModel(CompetitionGuestModel guest) {
        return new SimpleRegisterComb(guest.getId() * -1, guest.getFname(), guest.getLname(),
                guest.getGenre(), guest.getCountry(), guest.getCategorie(),
                new SimpleClubModel(null, guest.getClub(), "fr", null),
                null, guest.getWeight(), guest.getWeightReal(), 0, false, false,
                new ArrayList<>());
    }

    public SimpleRegisterComb setCategorieInscrite(List<CatPresetModel> presets) {
        this.categoriesInscrites = presets.stream().map(CatPresetModel::getId).toList();
        return this;
    }
}
