package com.gcsc.connection.apikey.dto;

import com.gcsc.connection.apikey.entity.SnpApiKey;

import java.time.LocalDateTime;

public record ApiKeyDetailResponse(
    Long apiKeyId,
    String keyName,
    String apiKeyPrefix,
    String decryptedKey,
    String status,
    Long userId,
    String userName,
    LocalDateTime expiresAt,
    LocalDateTime lastUsedAt,
    LocalDateTime createdAt
) {

    public static ApiKeyDetailResponse from(SnpApiKey key, String decryptedKey) {
        return new ApiKeyDetailResponse(
            key.getApiKeyId(),
            key.getKeyName(),
            key.getApiKeyPrefix(),
            decryptedKey,
            key.getStatus().name(),
            key.getUser().getUserId(),
            key.getUser().getUserName(),
            key.getExpiresAt(),
            key.getLastUsedAt(),
            key.getCreatedAt()
        );
    }
}
