package dev.photosync.core.provider;

/**
 * The two things every token-authenticated photo backend needs: where it lives
 * and how we prove who we are.
 *
 * <p>Deliberately not a provider-specific credential bag. Immich calls these a
 * server URL and an API key; a future backend may call them something else, and
 * the labels come from {@link ProviderDescriptor} rather than from here.
 */
public record ProviderConnection(String endpoint, String secret) {

    public ProviderConnection {
        endpoint = endpoint == null ? "" : endpoint.trim();
        secret = secret == null ? "" : secret.trim();
    }

    public static ProviderConnection empty() {
        return new ProviderConnection("", "");
    }

    public boolean isConfigured() {
        return !endpoint.isEmpty() && !secret.isEmpty();
    }

    /**
     * Redacted on purpose. This record ends up in exception messages and debug
     * logs, and an API key in a pasted log is a real leak.
     */
    @Override
    public String toString() {
        return "ProviderConnection[endpoint=" + endpoint
                + ", secret=" + (secret.isEmpty() ? "<unset>" : "<redacted>") + "]";
    }
}
