package fr.titionfire.ffsaf.rest.data;

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.List;

@Data
@AllArgsConstructor
@RegisterForReflection
public class MatchData {
    private Long id;
    private Long c1_id;
    private String c1_str;
    private Long c2_id;
    private String c2_str;
    private Long category;
    private long category_ord;
    private boolean isEnd = true;
    private char poule;
    private List<ScoreEmbeddable> scores;

    public static MatchData fromModel(MatchModel model) {
        if (model == null)
            return null;

        return new MatchData(model.getSystemId(),
                (model.getC1_id() == null) ? null : model.getC1_id().getId(),
                (model.getC1_guest() == null) ? null : model.getC1_guest().getName(),
                (model.getC2_id() == null) ? null : model.getC2_id().getId(),
                (model.getC2_guest() == null) ? null : model.getC2_guest().getName(),
                model.getCategory().getId(), model.getCategory_ord(), model.isEnd(), model.getPoule(),
                model.getScores());
    }
}
