package com.livingworld.core.services;

/**
 * Immutable key used to identify and look up services in a service registry.
 *
 * @param <T> the type of the service this key identifies
 */
public record ServiceKey<T>(String id, Class<T> serviceType) {

    /**
     * Creates a new service key with validation.
     *
     * @param id          the unique identifier for the service (must not be null or blank)
     * @param serviceType the class type of the service (must not be null)
     * @throws IllegalArgumentException if {@code id} is null or blank, or {@code serviceType} is null
     */
    public ServiceKey {
        if (id == null || id.isBlank()) {
            throw new IllegalArgumentException("Service key id must not be null or blank");
        }
        if (serviceType == null) {
            throw new IllegalArgumentException("Service key serviceType must not be null");
        }
    }

    /**
     * Returns a stable string representation of this service key.
     *
     * @return formatted string with id and fully-qualified service type name
     */
    @Override
    public String toString() {
        return "ServiceKey{id='" + id + "', type='" + serviceType.getName() + "'}";
    }
}