package com.qqchen.deploy.backend.workflow.entity;

import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity;
import com.qqchen.deploy.backend.workflow.enums.FormDefinitionStatusEnums;
import com.vladmihalcea.hibernate.type.json.JsonType;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import java.util.List;
import java.util.Map;

/**
 * 表单定义实体
 *
 * @author qqchen
 * @date 2025-10-24
 */
@Data
@Table(name = "form_definition")
@jakarta.persistence.Entity
@EqualsAndHashCode(callSuper = true)
@LogicDelete
public class FormDefinition extends Entity<Long> {

    /**
     * 表单名称
     */
    @Column(nullable = false)
    private String name;

    /**
     * 表单标识（业务唯一）
     */
    @Column(name = "`key`", nullable = false)
    private String key;

    /**
     * 表单版本号
     */
    @Column(name = "form_version", nullable = false)
    private Integer formVersion;

    /**
     * 表单分类ID
     */
    @Column(name = "category_id")
    private Long categoryId;

    /**
     * 表单描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    /**
     * 表单Schema（前端设计器导出的JSON结构，原样存储）
     */
    @Type(JsonType.class)
    @Column(name = "`schema`", nullable = false, columnDefinition = "json")
    private Map<String, Object> schema;

    /**
     * 标签（用于分类和搜索）
     */
    @Type(JsonType.class)
    @Column(name = "tags", columnDefinition = "json")
    private List<String> tags;

    /**
     * 状态（DRAFT-草稿、PUBLISHED-已发布、DISABLED-已禁用）
     */
    @Column(name = "status", nullable = false)
    @Enumerated(EnumType.STRING)
    private FormDefinitionStatusEnums status;

    /**
     * 是否为模板
     */
    @Column(name = "is_template", nullable = false)
    private Boolean isTemplate;
}

