package de.effigenix.infrastructure.usermanagement.web.dto;

import de.effigenix.application.usermanagement.dto.SessionToken;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.OffsetDateTime;

/**
 * Response DTO for successful login.
 *
 * Contains JWT access token and refresh token.
 * Client should store the access token and send it in Authorization header
 * for subsequent requests.
 */
@Schema(description = "Login response with JWT tokens",
        requiredProperties = {"accessToken", "tokenType", "expiresIn", "expiresAt", "refreshToken"})
public record LoginResponse(
        @Schema(description = "JWT access token", example = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...")
        String accessToken,

        @Schema(description = "Token type", example = "Bearer")
        String tokenType,

        @Schema(description = "Token expiration time in seconds", example = "3600")
        long expiresIn,

        @Schema(description = "Token expiration timestamp")
        OffsetDateTime expiresAt,

        @Schema(description = "Refresh token for obtaining new access token")
        String refreshToken
) {
    /**
     * Creates a LoginResponse from a SessionToken.
     */
    public static LoginResponse from(SessionToken token) {
        return new LoginResponse(
                token.accessToken(),
                token.tokenType(),
                token.expiresIn(),
                token.expiresAt(),
                token.refreshToken()
        );
    }
}
