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

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

/**
 * 템플릿 Entity
 */
@Entity
@Table(name = "templates")
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TemplateEntity extends BaseTimeEntity {

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

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

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

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

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

    @Column(name = "is_public", nullable = false)
    @Builder.Default
    private Boolean isPublic = true;

    @Column(name = "created_by", length = 50, nullable = false)
    private String createdBy;

    public Template toDomain() {
        return Template.builder()
                .templateId(this.templateId)
                .name(this.name)
                .description(this.description)
                .category(this.category)
                .isPublic(this.isPublic)
                .createdBy(this.createdBy)
                .build();
    }

    public static TemplateEntity fromDomain(Template template) {
        return TemplateEntity.builder()
                .templateId(template.getTemplateId())
                .name(template.getName())
                .description(template.getDescription())
                .category(template.getCategory())
                .isPublic(template.getIsPublic())
                .createdBy(template.getCreatedBy())
                .build();
    }
}
