package org.qinan.safetyeval.domain.support;

import org.qinan.safetyeval.domain.entity.QualFilingReviewEntity;
import org.springframework.util.StringUtils;

/**
 * 资质备案专家核验判定（异地单位需专家核验）
 */
public final class QualFilingExpertCheckSupport {

    private static final String REMOTE_UNIT_KEYWORD = "异地";

    private QualFilingExpertCheckSupport() {
    }

    public static boolean needsExpertCheck(String filingUnitTypeName) {
        return StringUtils.hasText(filingUnitTypeName)
                && filingUnitTypeName.contains(REMOTE_UNIT_KEYWORD);
    }

    /**
     * @return arranging=待安排, pending=待核验, passed=已核验；本地单位返回 null
     */
    public static String resolveExpertStatus(String filingUnitTypeName, QualFilingReviewEntity review) {
        if (!needsExpertCheck(filingUnitTypeName)) {
            return null;
        }
        if (review == null || review.getFilingExpertId() == null) {
            return "arranging";
        }
        if ("1".equals(review.getReviewResult())) {
            return "passed";
        }
        return "pending";
    }
}
