package com.r35157.assetaz.services.cis;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

/**
 * Identifies a currency in an external identification system.
 *
 * <p>The semantic identity is the combination of {@link #namespace()} and
 * {@link #externalId()}. {@link #symbol()} is optional display metadata and
 * must not be used as a lookup key. Equality and hash codes therefore depend
 * only on the namespace and external ID.</p>
 *
 * @param namespace the external identification system, such as
 *                  {@value #SOLANA_MINT_NAMESPACE}; never {@code null}
 * @param externalId the identifier within the namespace, such as a token mint
 *                   address; never {@code null}
 * @param symbol optional symbol metadata supplied by the external system
 */
public record ExternalCurrencyReference(
        @NotNull String namespace,
        @NotNull String externalId,
        @Nullable String symbol
) {
    public ExternalCurrencyReference {
        Objects.requireNonNull(namespace, "namespace");
        Objects.requireNonNull(externalId, "externalId");
    }

    @Override
    public boolean equals(Object object) {
        return this == object
                || object instanceof ExternalCurrencyReference other
                && namespace.equals(other.namespace)
                && externalId.equals(other.externalId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(namespace, externalId);
    }

    /**
     * Namespace for tokens identified by their Solana mint address.
     */
    public static final String SOLANA_MINT_NAMESPACE = "solana-mint";
}
