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

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

/**
 * 회의록 섹션 Entity
 * 참석자가 작성한 메모를 안건별로 저장
 * AI 분석의 입력 데이터로 사용됨
 */
@Entity
@Table(name = "minutes_sections")
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MinutesSectionEntity extends BaseTimeEntity {

    @Id
    @Column(name = "id", length = 50)
    private String id;

    @Column(name = "minutes_id", nullable = false, length = 50)
    private String minutesId;

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

    @Column(name = "title", length = 200)
    private String title;

    @Column(name = "content", columnDefinition = "TEXT")
    private String content;

    @Column(name = "order")
    private Integer order;

    @Column(name = "verified")
    private Boolean verified;

    @Column(name = "locked")
    private Boolean locked;

    @Column(name = "locked_by", length = 50)
    private String lockedBy;

    public MinutesSection toDomain() {
        return MinutesSection.builder()
                .sectionId(this.id)
                .minutesId(this.minutesId)
                .type(this.type)
                .title(this.title)
                .content(this.content)
                .order(this.order)
                .verified(this.verified)
                .locked(this.locked)
                .lockedBy(this.lockedBy)
                .build();
    }

    public static MinutesSectionEntity fromDomain(MinutesSection section) {
        return MinutesSectionEntity.builder()
                .id(section.getSectionId())
                .minutesId(section.getMinutesId())
                .type(section.getType())
                .title(section.getTitle())
                .content(section.getContent())
                .order(section.getOrder())
                .verified(section.getVerified())
                .locked(section.getLocked())
                .lockedBy(section.getLockedBy())
                .build();
    }

    public void verify() {
        this.verified = true;
    }

    public void lock(String userId) {
        this.locked = true;
        this.lockedBy = userId;
    }

    public void unlock() {
        this.locked = false;
        this.lockedBy = null;
    }
}
