package fr.titionfire.ffsaf.rest.data;

import fr.titionfire.ffsaf.data.model.AffiliationRequestModel;
import fr.titionfire.ffsaf.utils.RoleAsso;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.List;

@Data
@Builder
@AllArgsConstructor
@RegisterForReflection
public class SimpleReqAffiliation {
    @Schema(description = "Identifiant de la demande d'affiliation", example = "1")
    Long id;
    @Schema(description = "Identifiant du club", example = "1")
    Long club;
    @Schema(description = "Nom du club si club similar trouver (même siret)", example = "Association sportive")
    String club_name;
    @Schema(description = "Identifiant du club affilié", example = "1")
    Long club_no_aff;
    @Schema(description = "Nom du club demander", example = "Association sportive")
    String name;
    @Schema(description = "Numéro SIRET ou RNA de l'association", example = "12345678901234")
    String stateId;
    @Schema(description = "Adresse de l'association", example = "1 rue de l'exemple, 75000 Paris")
    String address;
    @Schema(description = "Email de contact de l'association", example = "test@test.fr")
    String contact;
    @Schema(description = "Liste des membres pour la demande d'affiliation")
    List<AffiliationMember> members;
    @Schema(description = "Saison de l'affiliation", example = "2025")
    int saison;

    public static SimpleReqAffiliation fromModel(AffiliationRequestModel model) {
        if (model == null)
            return null;

        return new SimpleReqAffiliation.SimpleReqAffiliationBuilder()
                .id(model.getId())
                .name(model.getName())
                .stateId(model.getState_id())
                .address(model.getAddress())
                .saison(model.getSaison())
                .contact(model.getContact())
                .members(List.of(
                        new AffiliationMember(model.getM1_lname(), model.getM1_fname(), model.getM1_email(),
                                model.getM1_lincence(), model.getM1_role()),
                        new AffiliationMember(model.getM2_lname(), model.getM2_fname(), model.getM2_email(),
                                model.getM2_lincence(), model.getM2_role()),
                        new AffiliationMember(model.getM3_lname(), model.getM3_fname(), model.getM3_email(),
                                model.getM3_lincence(), model.getM3_role())
                ))
                .build();
    }

    @Data
    @AllArgsConstructor
    @RegisterForReflection
    public static class AffiliationMember {
        @Schema(description = "Nom du membre", example = "Doe")
        String lname;
        @Schema(description = "Prénom du membre", example = "John")
        String fname;
        @Schema(description = "Email du membre", example = "john.doe@test.com")
        String email;
        @Schema(description = "Numéro de licence du membre", example = "12345")
        int licence;
        @Schema(description = "Rôle du membre", example = "MEMBRE")
        RoleAsso role;
    }
}
