/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import type { RatioType } from '../types' import { RATIO_TYPE_OPTIONS } from './constants' export type RatioDifferenceEntry = { current: number | string | null upstreams: Record confidence: Record } export type ModelRow = { key: string model: string ratioTypes: Partial> billingConflict: boolean } export type ResolutionsMap = Record> export const RATIO_SYNC_FIELDS: RatioType[] = [ 'model_ratio', 'completion_ratio', 'cache_ratio', 'create_cache_ratio', 'image_ratio', 'audio_ratio', 'audio_completion_ratio', ] export const SYNC_FIELD_ORDER: RatioType[] = [ ...RATIO_SYNC_FIELDS, 'model_price', 'billing_mode', 'billing_expr', ] export const NUMERIC_SYNC_FIELDS = new Set([ ...RATIO_SYNC_FIELDS, 'model_price', ]) export function getSyncFieldLabel( ratioType: string, t: (key: string) => string ): string { const opt = RATIO_TYPE_OPTIONS.find((o) => o.value === ratioType) if (opt) return t(opt.label) return ratioType } export function getOrderedRatioTypes( ratioTypes: Partial>, filter?: string ): RatioType[] { const keys = Object.keys(ratioTypes) as RatioType[] const ordered = [ ...SYNC_FIELD_ORDER.filter((f) => keys.includes(f)), ...keys.filter((f) => !SYNC_FIELD_ORDER.includes(f)), ] if (!filter || filter === '__all__') return ordered return ordered.filter((f) => f === filter) } export function getPreferredSyncField( ratioTypes: Partial>, ratioType: RatioType, sourceName: string ): RatioType { const exprValue = ratioTypes.billing_expr?.upstreams?.[sourceName] if ( ratioType !== 'billing_expr' && exprValue !== null && exprValue !== undefined && exprValue !== 'same' ) { return 'billing_expr' } return ratioType } export function isSelectableUpstreamValue( value: number | string | 'same' | null | undefined ): boolean { return value !== null && value !== undefined && value !== 'same' }