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;

/**
 * 운영자 액션 로그 (도메인 컨텍스트 보존).
 * audit_log와 별개로 group_key 등 도메인 정보를 직접 저장.
 */
@Entity
@Table(name = "gear_group_parent_review_log", schema = "kcg")
@Getter @Setter @NoArgsConstructor @AllArgsConstructor @Builder
public class ParentReviewLog {

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

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

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

    @Column(name = "action", nullable = false, length = 30)
    private String action;  // CONFIRM, REJECT, RESET, EXCLUDE_GROUP, EXCLUDE_GLOBAL, LABEL_PARENT, CANCEL_LABEL, RELEASE_EXCLUSION

    @Column(name = "selected_parent_mmsi", length = 20)
    private String selectedParentMmsi;

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

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

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

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

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