package com.unicorn.hgzero.meeting.infra.gateway.entity;

import com.unicorn.hgzero.common.entity.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 회의 참석자 Entity
 * meeting_id와 user_id를 복합키로 사용하여 다대다 관계 표현
 */
@Entity
@Table(name = "meeting_participants")
@IdClass(MeetingParticipantId.class)
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MeetingParticipantEntity extends BaseTimeEntity {

    /**
     * 회의 ID (복합키)
     */
    @Id
    @Column(name = "meeting_id", length = 50)
    private String meetingId;

    /**
     * 사용자 ID (이메일) (복합키)
     */
    @Id
    @Column(name = "user_id", length = 100)
    private String userId;

    /**
     * 초대 상태 (PENDING, ACCEPTED, DECLINED)
     */
    @Column(name = "invitation_status", length = 20)
    @Builder.Default
    private String invitationStatus = "PENDING";

    /**
     * 참석 여부
     */
    @Column(name = "attended")
    @Builder.Default
    private Boolean attended = false;

    /**
     * 회의 엔티티와의 관계
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "meeting_id", insertable = false, updatable = false)
    private MeetingEntity meeting;

    /**
     * 초대 수락
     */
    public void accept() {
        this.invitationStatus = "ACCEPTED";
    }

    /**
     * 초대 거절
     */
    public void decline() {
        this.invitationStatus = "DECLINED";
    }

    /**
     * 참석 처리
     */
    public void markAsAttended() {
        this.attended = true;
    }
}
