package de.gecheckt.pdf.umbenenner.adapter.in.gui.editor;

import java.util.Objects;

/**
 * Editable GUI state for one provider-family configuration block.
 * <p>
 * The fields are stored as editor-friendly strings so later GUI layers can bind them directly
 * to text-based controls without prematurely parsing or validating them.
 *
 * @param baseUrl provider endpoint base URL as editable text
 * @param model model identifier as editable text
 * @param timeoutSeconds timeout value as editable text
 * @param apiKey API-key state for the provider
 */
public record GuiProviderConfigurationState(
        String baseUrl,
        String model,
        String timeoutSeconds,
        GuiProviderApiKeyState apiKey) {

    /**
     * Creates a provider configuration state with all text fields blank and the API key unresolved.
     *
     * @return a blank provider configuration state
     */
    public static GuiProviderConfigurationState blank() {
        return new GuiProviderConfigurationState("", "", "", GuiProviderApiKeyState.unresolved());
    }

    /**
     * Creates a new provider configuration state.
     *
     * @param baseUrl provider endpoint base URL; {@code null} becomes an empty string
     * @param model model identifier; {@code null} becomes an empty string
     * @param timeoutSeconds timeout value; {@code null} becomes an empty string
     * @param apiKey API-key state; when {@code null}, an unresolved blank key state is used
     */
    public GuiProviderConfigurationState {
        baseUrl = baseUrl == null ? "" : baseUrl;
        model = model == null ? "" : model;
        timeoutSeconds = timeoutSeconds == null ? "" : timeoutSeconds;
        apiKey = Objects.requireNonNullElse(apiKey, GuiProviderApiKeyState.unresolved());
    }
}
