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

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

import java.util.List;

/**
 * 团队环境配置实体
 *
 * <p>定义团队对特定环境的配置：
 * <ul>
 *   <li>审批配置：是否需要审批、审批人列表</li>
 *   <li>通知配置：通知渠道、是否启用</li>
 *   <li>安全策略：代码审查要求</li>
 * </ul>
 *
 * <p>数据迁移说明：
 * 本表由 deploy_team_config 重构而来，将原来的 JSON 数组结构展开为标准表结构：
 * <pre>
 * 原结构：1条记录 = 1个团队的多个环境配置（JSON数组）
 * 新结构：1条记录 = 1个团队在1个环境的配置
 * </pre>
 *
 * @author qqchen
 * @since 2025-11-04
 */
@Data
@EqualsAndHashCode(callSuper = true)
@jakarta.persistence.Entity
@Table(name = "deploy_team_environment_config")
@LogicDelete(false)
public class TeamEnvironmentConfig extends Entity<Long> {

    // ===== 关联关系 =====

    /**
     * 团队ID
     */
    @Column(name = "team_id", nullable = false)
    private Long teamId;

    /**
     * 环境ID
     */
    @Column(name = "environment_id", nullable = false)
    private Long environmentId;

    // ===== 审批配置 =====

    /**
     * 是否需要审批
     * <p>对应原 TeamConfig.environmentApprovalRequired[i]
     */
    @Column(name = "approval_required", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE")
    private Boolean approvalRequired = false;

    /**
     * 审批人用户ID列表
     * <p>对应原 TeamConfig.approverUserIds[i]
     * <p>示例：[1, 4, 7]
     */
    @Type(JsonType.class)
    @Column(name = "approver_user_ids", columnDefinition = "JSON")
    private List<Long> approverUserIds;


    /**
     * 是否要求代码审查通过才能部署
     */
    @Column(name = "require_code_review", nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE")
    private Boolean requireCodeReview = false;

    // ===== 备注 =====

    /**
     * 备注信息
     */
    @Column(name = "remark", length = 500)
    private String remark;
}

