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

import com.ruoyi.common.utils.StringUtils;

/**
 * 畜牧医疗资源常量与规则。
 */
public final class MedicalResourceRules
{
    /** 兽医人员（biz_information_category） */
    public static final String RESOURCE_TYPE_VET = "004001";

    /** 专家团队 */
    public static final String RESOURCE_TYPE_TEAM = "004002";

    /** 诊疗机构 */
    public static final String RESOURCE_TYPE_ORG = "004003";

    /** 医疗设备 */
    public static final String RESOURCE_TYPE_EQUIPMENT = "004004";

    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_VET = "vet";

    /** 诊疗机构平台角色权限字符（sys_role.role_key） */
    public static final String ROLE_KEY_INS = "ins";

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

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

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

    public static final int MIN_NAME_LEN = 1;

    public static final int MAX_NAME_LEN = 10;

    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_TEAM_MEMBERS_LEN = 500;

    public static final int MAX_MODEL_LEN = 10;

    public static final int MAX_REMARK_LEN = 500;

    public static final int ORG_LEVEL_CLINIC = 1;

    public static final int ORG_LEVEL_HOSPITAL = 2;

    public static final int CONSULT_MODE_FIXED = 1;

    public static final int CONSULT_MODE_HOME = 2;

    public static final int CONSULT_MODE_ONLINE = 3;

    private MedicalResourceRules()
    {
    }

    public static boolean isResourceTypeValid(String type)
    {
        if (StringUtils.isEmpty(type))
        {
            return false;
        }
        return RESOURCE_TYPE_VET.equals(type)
                || RESOURCE_TYPE_TEAM.equals(type)
                || RESOURCE_TYPE_ORG.equals(type)
                || RESOURCE_TYPE_EQUIPMENT.equals(type);
    }

    public static boolean canAssignAccount(String resourceType)
    {
        return RESOURCE_TYPE_VET.equals(resourceType) || RESOURCE_TYPE_ORG.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 isPhotoExtensionAllowed(String path)
    {
        if (path == null)
        {
            return false;
        }
        String lower = path.toLowerCase();
        return lower.endsWith(".jpg") || lower.endsWith(".jpeg") || lower.endsWith(".png");
    }

    public static String roleKeyForAssign(String resourceType)
    {
        if (RESOURCE_TYPE_VET.equals(resourceType))
        {
            return ROLE_KEY_VET;
        }
        if (RESOURCE_TYPE_ORG.equals(resourceType))
        {
            return ROLE_KEY_INS;
        }
        throw new IllegalArgumentException("resourceType cannot assign account");
    }
}
