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

import java.math.BigDecimal;
import com.ruoyi.common.utils.StringUtils;

/**
 * 畜牧科技资源常量与规则。
 */
public final class TechResourceRules
{
    /** 专家（biz_information_category） */
    public static final String RESOURCE_TYPE_EXPERT = "004005";

    /** 技术成果 */
    public static final String RESOURCE_TYPE_ACHIEVEMENT = "004006";

    /** 共享仪器 */
    public static final String RESOURCE_TYPE_INSTRUMENT = "004007";

    /** 视频课程 */
    public static final String RESOURCE_TYPE_VIDEO = "004008";

    /** 课程主题：基础养殖 */
    public static final String COURSE_TOPIC_BASIC = "005001";

    /** 课程主题：疫病防治 */
    public static final String COURSE_TOPIC_DISEASE = "005002";

    /** 课程主题：繁育技术 */
    public static final String COURSE_TOPIC_BREEDING = "005003";

    /** 课程主题：政策解读 */
    public static final String COURSE_TOPIC_POLICY = "005004";

    public static final int PUBLISH_STATUS_DRAFT = 0;

    public static final int PUBLISH_STATUS_PUBLISHED = 1;

    public static final int QUERY_PUBLISH_UNPUBLISHED = 0;

    public static final int QUERY_PUBLISH_PUBLISHED = 1;

    public static final int QUERY_PUBLISH_OFFLINE = 2;

    public static final int ACCOUNT_ASSIGNED_NO = 0;

    public static final int ACCOUNT_ASSIGNED_YES = 1;

    public static final String DEL_FLAG_NORMAL = "0";

    public static final String DEL_FLAG_DELETED = "2";

    /** 专家平台角色权限字符（sys_role.role_key） */
    public static final String ROLE_KEY_EXPERT = "exp";

    public static final String MSG_ROLE_NOT_FOUND = "未配置权限字符为「%s」的角色，无法分配账号";

    /**
     * 历史常量；分配账号请使用 {@link #ROLE_KEY_EXPERT} 解析角色。
     */
    public static final long ROLE_ID_EXPERT = 101L;

    public static final int MIN_NAME_LEN = 1;

    public static final int MAX_NAME_LEN_SHORT = 10;

    public static final int MAX_NAME_LEN_LONG = 20;

    public static final int MAX_INTRO_LEN = 500;

    public static final int MAX_UNIT_LEN = 20;

    public static final int MAX_ADDRESS_LEN = 100;

    public static final int MAX_SERVICE_AREA_LEN = 100;

    public static final int MAX_DIRECTION_LEN = 20;

    public static final int MAX_MODEL_LEN = 10;

    public static final int MAX_REMARK_LEN = 500;

    /** 专家默认评分（五星） */
    public static final BigDecimal DEFAULT_EXPERT_RATING = new BigDecimal("5.0");

    private TechResourceRules()
    {
    }

    public static boolean isResourceTypeValid(String type)
    {
        if (StringUtils.isEmpty(type))
        {
            return false;
        }
        return RESOURCE_TYPE_EXPERT.equals(type)
                || RESOURCE_TYPE_ACHIEVEMENT.equals(type)
                || RESOURCE_TYPE_INSTRUMENT.equals(type)
                || RESOURCE_TYPE_VIDEO.equals(type);
    }

    public static int maxNameLength(String resourceType)
    {
        if (RESOURCE_TYPE_ACHIEVEMENT.equals(resourceType) || RESOURCE_TYPE_VIDEO.equals(resourceType))
        {
            return MAX_NAME_LEN_LONG;
        }
        return MAX_NAME_LEN_SHORT;
    }

    public static boolean canAssignAccount(String resourceType)
    {
        return RESOURCE_TYPE_EXPERT.equals(resourceType);
    }

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

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

    public static boolean canDelete(Integer publishStatus)
    {
        return canEdit(publishStatus);
    }

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

    public static boolean canOffline(Integer publishStatus)
    {
        return isPublished(publishStatus);
    }

    public static boolean isImageExtensionAllowed(String path)
    {
        if (path == null)
        {
            return false;
        }
        String lower = path.toLowerCase();
        return lower.endsWith(".jpg") || lower.endsWith(".jpeg") || lower.endsWith(".png");
    }

    public static boolean isVideoExtensionAllowed(String path)
    {
        return path != null && path.toLowerCase().endsWith(".mp4");
    }
}
