"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isModelCapacityExhausted = exports.buildProviderEntitlementEvidence = exports.getProviderTierLabel = exports.normalizeProviderTierId = void 0;
const RAW_TIER_LABELS = {
    'free-tier': 'Free',
    'legacy-tier': 'Legacy',
    'standard-tier': 'Standard',
    'g1-pro-tier': 'Pro',
    'g1-ultra-tier': 'Ultra',
};
function normalizeProviderTierId(rawTierId) {
    if (!rawTierId)
        return 'unknown';
    const normalized = rawTierId.trim().toLowerCase();
    if (!normalized)
        return 'unknown';
    if (normalized.includes('ultra'))
        return 'ultra';
    if (normalized.includes('pro'))
        return 'pro';
    if (normalized.includes('free') || normalized.includes('legacy'))
        return 'free';
    return 'unknown';
}
exports.normalizeProviderTierId = normalizeProviderTierId;
function getProviderTierLabel(rawTierId) {
    if (!rawTierId)
        return null;
    const normalized = rawTierId.trim().toLowerCase();
    return normalized ? (RAW_TIER_LABELS[normalized] ?? rawTierId.trim()) : null;
}
exports.getProviderTierLabel = getProviderTierLabel;
function buildProviderEntitlementEvidence(input) {
    const rawTierId = input.rawTierId?.trim() || null;
    return {
        normalizedTier: input.normalizedTier,
        rawTierId,
        rawTierLabel: input.rawTierLabel ?? getProviderTierLabel(rawTierId),
        source: input.source,
        confidence: input.confidence,
        accessState: input.accessState,
        capacityState: input.capacityState,
        notes: input.notes ?? null,
        lastVerifiedAt: input.lastVerifiedAt ?? Date.now(),
    };
}
exports.buildProviderEntitlementEvidence = buildProviderEntitlementEvidence;
function isModelCapacityExhausted(message, detail, errorCode) {
    const haystack = `${message || ''} ${detail || ''} ${errorCode || ''}`.toLowerCase();
    return (haystack.includes('model_capacity_exhausted') ||
        haystack.includes('no capacity available') ||
        haystack.includes('capacity exhausted'));
}
exports.isModelCapacityExhausted = isModelCapacityExhausted;
//# sourceMappingURL=provider-entitlement-evidence.js.map