package com.ruoyi.web.modules.technology.support;

/**
 * 实战业务培训常量与发布状态规则。
 */
public final class PracticalTrainingRules
{
    public static final int PUBLISH_STATUS_DRAFT = 0;

    public static final int PUBLISH_STATUS_PUBLISHED = 1;

    public static final int ENROLL_STATUS_NOT_STARTED = 1;

    public static final int ENROLL_STATUS_ENROLLING = 2;

    public static final int ENROLL_STATUS_FULL = 3;

    public static final int ENROLL_STATUS_CLOSED = 4;

    /** 培训状态（入库 biz_practical_training.training_status） */
    public static final String TRAINING_STATUS_NOT_STARTED = "006001";

    public static final String TRAINING_STATUS_ENROLLING = "006002";

    public static final String TRAINING_STATUS_FULL = "006003";

    public static final String TRAINING_STATUS_CLOSED = "006004";

    /** 成员报名：0 已报名 1 已取消 */
    public static final int MEMBER_ENROLL_ACTIVE = 0;

    public static final int MEMBER_ENROLL_CANCELLED = 1;

    public static final String DEL_FLAG_NORMAL = "0";

    public static final String DEL_FLAG_DELETED = "2";

    public static final int MIN_TOPIC_LEN = 1;

    public static final int MAX_TOPIC_LEN = 20;

    public static final int MAX_INTRO_LEN = 500;

    public static final int MIN_LOCATION_LEN = 1;

    public static final int MAX_LOCATION_LEN = 200;

    public static final int MAX_REMARK_LEN = 500;

    private PracticalTrainingRules()
    {
    }

    public static boolean canEdit(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == PUBLISH_STATUS_DRAFT;
    }

    public static boolean canDelete(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == PUBLISH_STATUS_DRAFT;
    }

    public static boolean canPublish(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == PUBLISH_STATUS_DRAFT;
    }

    public static boolean canOffline(Integer publishStatus)
    {
        return publishStatus != null && publishStatus == PUBLISH_STATUS_PUBLISHED;
    }

    public static boolean isCoverExtensionAllowed(String filenameOrPath)
    {
        String ext = extensionOf(filenameOrPath);
        return "jpg".equals(ext) || "jpeg".equals(ext) || "png".equals(ext);
    }

    public static String extensionOf(String name)
    {
        if (name == null)
        {
            return "";
        }
        int i = name.lastIndexOf('.');
        if (i < 0 || i == name.length() - 1)
        {
            return "";
        }
        return name.substring(i + 1).toLowerCase();
    }

    public static String enrollStatusName(int enrollStatus)
    {
        switch (enrollStatus)
        {
            case ENROLL_STATUS_ENROLLING:
                return "报名中";
            case ENROLL_STATUS_FULL:
                return "已报满";
            case ENROLL_STATUS_CLOSED:
                return "已截止";
            case ENROLL_STATUS_NOT_STARTED:
            default:
                return "未开始";
        }
    }

    public static String trainingStatusName(String trainingStatus)
    {
        if (TRAINING_STATUS_ENROLLING.equals(trainingStatus))
        {
            return "报名中";
        }
        if (TRAINING_STATUS_FULL.equals(trainingStatus))
        {
            return "已报满";
        }
        if (TRAINING_STATUS_CLOSED.equals(trainingStatus))
        {
            return "已截止";
        }
        return "未开始";
    }

    public static boolean canCancelEnrollment(String trainingStatus)
    {
        return trainingStatus != null && !TRAINING_STATUS_CLOSED.equals(trainingStatus);
    }

    public static int enrollStatusFromTrainingStatus(String trainingStatus)
    {
        if (TRAINING_STATUS_ENROLLING.equals(trainingStatus))
        {
            return ENROLL_STATUS_ENROLLING;
        }
        if (TRAINING_STATUS_FULL.equals(trainingStatus))
        {
            return ENROLL_STATUS_FULL;
        }
        if (TRAINING_STATUS_CLOSED.equals(trainingStatus))
        {
            return ENROLL_STATUS_CLOSED;
        }
        return ENROLL_STATUS_NOT_STARTED;
    }
}
