import { ActivityAction } from "@prisma/client";
import { IsOptional, IsEnum, IsInt, Min, Max, IsDateString, IsUUID } from "class-validator";
import { Type } from "class-transformer";

/**
 * DTO for querying credential audit logs with filters and pagination
 * All fields are optional - omitted filters are not applied
 */
export class QueryCredentialAuditDto {
  /**
   * Filter by specific credential ID
   * Optional - if omitted, returns audit logs for all credentials in workspace
   */
  @IsOptional()
  @IsUUID("4", { message: "credentialId must be a valid UUID" })
  credentialId?: string;

  /**
   * Filter by activity action type
   * Optional - supported actions:
   * - CREDENTIAL_CREATED
   * - CREDENTIAL_ACCESSED
   * - CREDENTIAL_ROTATED
   * - CREDENTIAL_REVOKED
   * - UPDATED (for metadata changes)
   */
  @IsOptional()
  @IsEnum(ActivityAction, { message: "action must be a valid ActivityAction" })
  action?: ActivityAction;

  /**
   * Filter by start date (inclusive)
   * Optional ISO 8601 date string
   */
  @IsOptional()
  @IsDateString({}, { message: "startDate must be a valid ISO 8601 date string" })
  startDate?: Date;

  /**
   * Filter by end date (inclusive)
   * Optional ISO 8601 date string
   */
  @IsOptional()
  @IsDateString({}, { message: "endDate must be a valid ISO 8601 date string" })
  endDate?: Date;

  /**
   * Page number (1-indexed)
   * Optional - defaults to 1
   */
  @IsOptional()
  @Type(() => Number)
  @IsInt({ message: "page must be an integer" })
  @Min(1, { message: "page must be at least 1" })
  page?: number = 1;

  /**
   * Results per page
   * Optional - defaults to 20, max 100
   */
  @IsOptional()
  @Type(() => Number)
  @IsInt({ message: "limit must be an integer" })
  @Min(1, { message: "limit must be at least 1" })
  @Max(100, { message: "limit must not exceed 100" })
  limit?: number = 20;
}
