import { ApiProperty } from "@nestjs/swagger";
import { ApiKeyEnvironment, ApiKeyScope, ApiKeyType } from "@prisma/client";

export class ApiKeyDto {
  @ApiProperty({ example: "key_01HXYZABCDEFGHJKMNPQRSTV" })
  id!: string;

  @ApiProperty({ enum: ApiKeyType, example: ApiKeyType.secret })
  type!: ApiKeyType;

  @ApiProperty({ enum: ApiKeyEnvironment, example: ApiKeyEnvironment.test })
  environment!: ApiKeyEnvironment;

  @ApiProperty({
    example: "sk_test_5f3a9b2c1d8e",
    description: "Primeros caracteres del valor de la key. Único y seguro de mostrar.",
  })
  prefix!: string;

  @ApiProperty({ enum: ApiKeyScope, example: ApiKeyScope.full })
  scope!: ApiKeyScope;

  @ApiProperty({ required: false, nullable: true, example: "Backend de producción" })
  label!: string | null;

  @ApiProperty({ required: false, nullable: true, example: "2026-06-07T14:30:00.000Z" })
  lastUsedAt?: Date | null;

  @ApiProperty({ required: false, nullable: true, example: null })
  revokedAt?: Date | null;

  @ApiProperty({ example: "2026-06-07T14:30:00.000Z" })
  createdAt!: Date;
}

export class CreatedApiKeyDto extends ApiKeyDto {
  @ApiProperty({
    example: "sk_test_5f3a9b2c1d8e7f4a3b2c1d8e7f4a3b2c1d8e7f4a3b2c1d8e",
    description:
      "Valor completo de la API key. **Se devuelve UNA sola vez** en la creación. Guardalo de forma segura: no se puede recuperar después.",
  })
  secret!: string;
}
