import { CredentialType, CredentialScope } from "@prisma/client";
import {
  IsString,
  IsEnum,
  IsOptional,
  IsDateString,
  IsObject,
  MinLength,
  MaxLength,
} from "class-validator";

/**
 * DTO for creating a new user credential
 */
export class CreateCredentialDto {
  @IsString({ message: "name must be a string" })
  @MinLength(1, { message: "name must not be empty" })
  @MaxLength(255, { message: "name must not exceed 255 characters" })
  name!: string;

  @IsString({ message: "provider must be a string" })
  @MinLength(1, { message: "provider must not be empty" })
  @MaxLength(100, { message: "provider must not exceed 100 characters" })
  provider!: string;

  @IsEnum(CredentialType, { message: "type must be a valid CredentialType" })
  type!: CredentialType;

  @IsOptional()
  @IsEnum(CredentialScope, { message: "scope must be a valid CredentialScope" })
  scope?: CredentialScope;

  @IsString({ message: "value must be a string" })
  @MinLength(1, { message: "value must not be empty" })
  value!: string;

  @IsOptional()
  @IsString({ message: "description must be a string" })
  @MaxLength(1000, { message: "description must not exceed 1000 characters" })
  description?: string;

  @IsOptional()
  @IsDateString({}, { message: "expiresAt must be a valid ISO 8601 date string" })
  expiresAt?: Date;

  @IsOptional()
  @IsObject({ message: "metadata must be an object" })
  metadata?: Record<string, unknown>;
}
