package fr.titionfire.ffsaf.domain.entity;

import fr.titionfire.ffsaf.data.model.MatchModel;
import fr.titionfire.ffsaf.utils.ScoreEmbeddable;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@RegisterForReflection
public class MatchEntity {
    private long id;
    private CombEntity c1;
    private CombEntity c2;
    private long categorie_ord = 0;
    private boolean isEnd;
    private long categorie;
    private Date date;
    private List<ScoreEmbeddable> scores;
    private char poule;

    public static MatchEntity fromModel(MatchModel model) {
        if (model == null)
            return null;
        return new MatchEntity(model.getId(),
                (model.getC1_id() == null) ? CombEntity.fromModel(model.getC1_guest()) : CombEntity.fromModel(
                        model.getC1_id()),
                (model.getC2_id() == null) ? CombEntity.fromModel(model.getC2_guest()) : CombEntity.fromModel(
                        model.getC2_id()),
                model.getCategory_ord(), model.isEnd(), model.getCategory().getId(), model.getDate(),
                model.getScores(),
                model.getPoule());
    }
}
