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

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.diagnosis.support.ServiceAppointmentRules;

/**
 * 预约服务 — 可预约资源类型与分页规则。
 */
public final class AppointmentResourceRules
{
    public static final String TYPE_VET = "004001";

    public static final String TYPE_ORG = "004003";

    public static final String TYPE_EXPERT = "004005";

    public static final int DEFAULT_PAGE_NUM = 1;

    public static final int DEFAULT_PAGE_SIZE = 10;

    public static final int MAX_PAGE_SIZE = 50;

    public static final int DATE_LIST_SIZE = 7;

    public static final int MIN_WEEKDAY = 1;

    public static final int MAX_WEEKDAY = 7;

    public static final int MAX_APPOINTEE_NAME_LEN = 64;

    public static final int MAX_PHONE_LEN = 20;

    public static final int MAX_ADDRESS_LEN = 200;

    public static final int MAX_REQUIREMENT_LEN = 500;

    private static final Set<String> ALLOWED_RESOURCE_TYPES = Collections.unmodifiableSet(new HashSet<>(
            Arrays.asList(TYPE_VET, TYPE_ORG, TYPE_EXPERT)));

    private AppointmentResourceRules()
    {
    }

    public static boolean isAllowedResourceType(String resourceType)
    {
        return resourceType != null && ALLOWED_RESOURCE_TYPES.contains(resourceType.trim());
    }

    public static int resolveProviderType(String resourceType)
    {
        if (TYPE_VET.equals(resourceType))
        {
            return ServiceAppointmentRules.PROVIDER_TYPE_VET;
        }
        if (TYPE_ORG.equals(resourceType))
        {
            return ServiceAppointmentRules.PROVIDER_TYPE_ORG;
        }
        if (TYPE_EXPERT.equals(resourceType))
        {
            return ServiceAppointmentRules.PROVIDER_TYPE_EXPERT;
        }
        throw new IllegalArgumentException("unsupported resourceType: " + resourceType);
    }

    public static int resolveInitialStatus(String resourceType)
    {
        if (TYPE_ORG.equals(resourceType))
        {
            return ServiceAppointmentRules.STATUS_BOOKED;
        }
        return ServiceAppointmentRules.STATUS_PENDING;
    }

    public static boolean isValidWeekday(Integer weekday)
    {
        return weekday == null || (weekday >= MIN_WEEKDAY && weekday <= MAX_WEEKDAY);
    }

    public static String normalizeResourceName(String name)
    {
        return StringUtils.isNotEmpty(name) ? name.trim() : null;
    }
}
