package fr.titionfire.ffsaf.data.model;

import fr.titionfire.ffsaf.utils.Contact;
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.persistence.*;
import lombok.*;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.List;
import java.util.Map;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@RegisterForReflection

@Entity
@Table(name = "club")
public class ClubModel implements LoggableModel {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Schema(description = "Identifiant du club", example = "1")
    Long id;

    @Schema(description = "Identifiant long du club (UUID)", example = "b94f3167-3f6a-449c-a73b-ec84202bf07e")
    String clubId;

    @Schema(description = "Nom du club", example = "Association sportive")
    String name;

    @Schema(description = "Pays du club", example = "FR")
    String country;

    //@Enumerated(EnumType.STRING)
    @ElementCollection
    @CollectionTable(name = "club_contact_mapping",
            joinColumns = {@JoinColumn(name = "club_id", referencedColumnName = "id")})
    @MapKeyColumn(name = "contact_type")
    @Schema(description = "Les contacts du club", example = "{\"SITE\": \"www.test.com\", \"COURRIEL\": \"test@test.com\"}")
    Map<Contact, String> contact;

    @Column(columnDefinition = "TEXT")
    @Schema(description = "Liste des lieux d'entraînement", example = "[{\"text\":\"addr 1\",\"lng\":2.24654,\"lat\":52.4868658},{\"text\":\"addr 2\",\"lng\":2.88654,\"lat\":52.7865456}]")
    String training_location;

    @Column(columnDefinition = "TEXT")
    @Schema(description = "Liste des jours et horaires d'entraînement (jours 0-6, 0=>lundi) (temps en minute depuis 00:00, 122=>2h02)", example = "[{\"day\":0,\"time_start\":164,\"time_end\":240},{\"day\":3,\"time_start\":124,\"time_end\":250}]")
    String training_day_time;

    @Schema(description = "Contact interne du club", example = "john.doe@test.com")
    String contact_intern;

    @Schema(description = "Adresse postale du club", example = "1 rue de l'exemple, 75000 Paris")
    String address;

    @Schema(description = "Numéro SIRET ou RNA du club", example = "12345678901234")
    String StateId;

    @Schema(description = "Numéro d'affiliation du club", example = "12345")
    Long no_affiliation;

    @Schema(description = "Club international", example = "false")
    boolean international;

    @OneToMany(mappedBy = "club", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @Schema(description = "Liste des affiliations du club (optionnel)")
    List<AffiliationModel> affiliations;

    @Override
    public String getObjectName() {
        return this.name;
    }

    @Override
    public LogModel.ObjectType getObjectType() {
        return LogModel.ObjectType.Club;
    }
}
