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.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.diagnosis.support.ServiceAppointmentRules;

/**
 * 我的预约 — 状态 Tab 筛选规则。
 */
public final class MyAppointmentStatusTabRules
{
    public static final String TAB_ALL = "all";

    /** 未开始：status 0、1、5 */
    public static final String TAB_NOT_STARTED = "notStarted";

    /** 待评价：status=4 且无评价记录（专家） */
    public static final String TAB_PENDING_REVIEW = "pendingReview";

    /** 已完成：status=4 */
    public static final String TAB_COMPLETED = "completed";

    /** 已取消：status=3 */
    public static final String TAB_CANCELLED = "cancelled";

    private static final Set<String> ALLOWED_TABS = Collections.unmodifiableSet(new HashSet<>(
            Arrays.asList(TAB_ALL, TAB_NOT_STARTED, TAB_PENDING_REVIEW, TAB_COMPLETED, TAB_CANCELLED)));

    private MyAppointmentStatusTabRules()
    {
    }

    public static String normalizeTab(String statusTab)
    {
        if (StringUtils.isEmpty(statusTab))
        {
            throw new ServiceException("预约状态筛选不能为空");
        }
        String tab = statusTab.trim();
        if (!ALLOWED_TABS.contains(tab))
        {
            throw new ServiceException("预约状态筛选无效");
        }
        return tab;
    }

    public static boolean isValidProviderType(Integer providerType)
    {
        return providerType != null
                && (providerType == ServiceAppointmentRules.PROVIDER_TYPE_VET
                        || providerType == ServiceAppointmentRules.PROVIDER_TYPE_ORG
                        || providerType == ServiceAppointmentRules.PROVIDER_TYPE_EXPERT);
    }

    public static boolean canCancel(int status)
    {
        return status == ServiceAppointmentRules.STATUS_PENDING
                || status == ServiceAppointmentRules.STATUS_CONFIRMED
                || status == ServiceAppointmentRules.STATUS_BOOKED;
    }
}
