package gc.mda.kcg.domain.fleet;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.time.OffsetDateTime;
import java.util.UUID;

/**
 * 모선 후보 제외 (운영자 결정).
 * scope_type: GROUP(그룹 한정) / GLOBAL(전역, 모든 그룹에 적용)
 */
@Entity
@Table(name = "gear_parent_candidate_exclusions", schema = "kcg")
@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder
public class CandidateExclusion {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "scope_type", nullable = false, length = 20)
    private String scopeType;  // GROUP, GLOBAL

    @Column(name = "group_key", length = 255)
    private String groupKey;

    @Column(name = "sub_cluster_id")
    private Integer subClusterId;

    @Column(name = "excluded_mmsi", nullable = false, length = 20)
    private String excludedMmsi;

    @Column(name = "reason", columnDefinition = "text")
    private String reason;

    @JdbcTypeCode(SqlTypes.UUID)
    @Column(name = "actor")
    private UUID actor;

    @Column(name = "actor_acnt", length = 50)
    private String actorAcnt;

    @Column(name = "created_at", nullable = false)
    private OffsetDateTime createdAt;

    @Column(name = "released_at")
    private OffsetDateTime releasedAt;

    @JdbcTypeCode(SqlTypes.UUID)
    @Column(name = "released_by")
    private UUID releasedBy;

    @Column(name = "released_by_acnt", length = 50)
    private String releasedByAcnt;

    @PrePersist
    void prePersist() {
        if (createdAt == null) createdAt = OffsetDateTime.now();
    }
}
