package de.gecheckt.pdf.umbenenner.application.config.provider;

/**
 * Immutable multi-provider configuration model.
 * <p>
 * Represents the resolved configuration for both supported AI provider families
 * together with the selection of the one provider family that is active for this
 * application run.
 *
 * <h2>Invariants</h2>
 * <ul>
 *   <li>Exactly one provider family is active per run.</li>
 *   <li>Required fields are enforced only for the active provider; the inactive
 *       provider's configuration may be incomplete.</li>
 *   <li>Validation of these invariants is performed by the corresponding validator
 *       in the adapter layer, not by this record itself.</li>
 * </ul>
 *
 * @param activeProviderFamily   the selected provider family for this run; {@code null}
 *                               indicates that {@code ai.provider.active} was absent or
 *                               held an unrecognised value – the validator will reject this
 * @param openAiCompatibleConfig configuration for the OpenAI-compatible provider family
 * @param claudeConfig           configuration for the Anthropic Claude provider family
 */
public record MultiProviderConfiguration(
        AiProviderFamily activeProviderFamily,
        ProviderConfiguration openAiCompatibleConfig,
        ProviderConfiguration claudeConfig) {

    /**
     * Returns the {@link ProviderConfiguration} for the currently active provider family.
     *
     * @return the active provider's configuration, never {@code null} when
     *         {@link #activeProviderFamily()} is not {@code null}
     * @throws NullPointerException if {@code activeProviderFamily} is {@code null}
     */
    public ProviderConfiguration activeProviderConfiguration() {
        return switch (activeProviderFamily) {
            case OPENAI_COMPATIBLE -> openAiCompatibleConfig;
            case CLAUDE -> claudeConfig;
        };
    }
}
