package com.mosquito.project.persistence.entity;

/**
 * 活动状态常量
 * 对应PRD: 活动全生命周期状态机
 */
public final class ActivityStatus {

    public static final String DRAFT = "DRAFT";           // 草稿
    public static final String PENDING = "PENDING";       // 待审批
    public static final String IN_APPROVAL = "IN_APPROVAL"; // 审批中
    public static final String APPROVED = "APPROVED";     // 已审批通过
    public static final String REJECTED = "REJECTED";     // 已拒绝
    public static final String WAITING_PUBLISH = "WAITING_PUBLISH"; // 待发布
    public static final String RUNNING = "RUNNING";       // 运行中
    public static final String PAUSED = "PAUSED";         // 已暂停
    public static final String ENDED = "ENDED";           // 已结束
    public static final String ARCHIVED = "ARCHIVED";     // 已归档
    public static final String DELETED = "DELETED";       // 已删除

    // 兼容旧状态（用于迁移）
    public static final String DRAFT_LEGACY = "draft";
    public static final String PUBLISHED_LEGACY = "published";
    public static final String PAUSED_LEGACY = "paused";
    public static final String ENDED_LEGACY = "ended";

    private ActivityStatus() {}

    /**
     * 检查状态是否允许发布
     */
    public static boolean canPublish(String status) {
        return APPROVED.equals(status) || WAITING_PUBLISH.equals(status);
    }

    /**
     * 检查状态是否允许提交审批
     */
    public static boolean canSubmitForApproval(String status) {
        return DRAFT.equals(status) || REJECTED.equals(status);
    }

    /**
     * 检查状态是否允许直接删除（仅草稿可直接删除）
     */
    public static boolean canDirectDelete(String status) {
        return DRAFT.equals(status);
    }

    /**
     * 检查状态是否需要审批后删除（草稿可直接删除，已结束需审批）
     */
    public static boolean canDeleteWithApproval(String status) {
        return DRAFT.equals(status) || ENDED.equals(status);
    }

    /**
     * 检查状态是否允许删除（草稿可直接删除）
     */
    public static boolean canDelete(String status) {
        return DRAFT.equals(status);
    }

    /**
     * 兼容旧状态到新状态
     */
    public static String convertLegacyStatus(String legacyStatus) {
        if (legacyStatus == null) return DRAFT;
        return switch (legacyStatus.toLowerCase()) {
            case "draft" -> DRAFT;
            case "published" -> RUNNING;
            case "paused" -> PAUSED;
            case "ended" -> ENDED;
            default -> legacyStatus;
        };
    }
}
