/**
 * Identity Linking DTOs
 *
 * Data transfer objects for identity linking API endpoints.
 */

import { IsString, IsEmail, IsOptional, IsObject, IsArray, IsNumber } from "class-validator";
import { SanitizeObject } from "../../common/decorators/sanitize.decorator";

/**
 * DTO for verifying identity from remote instance
 */
export class VerifyIdentityDto {
  @IsString()
  localUserId!: string;

  @IsString()
  remoteUserId!: string;

  @IsString()
  remoteInstanceId!: string;

  @IsString()
  oidcToken!: string;

  @IsNumber()
  timestamp!: number;

  @IsString()
  signature!: string;
}

/**
 * DTO for resolving remote user to local user
 */
export class ResolveIdentityDto {
  @IsString()
  remoteInstanceId!: string;

  @IsString()
  remoteUserId!: string;
}

/**
 * DTO for reverse resolving local user to remote identity
 */
export class ReverseResolveIdentityDto {
  @IsString()
  localUserId!: string;

  @IsString()
  remoteInstanceId!: string;
}

/**
 * DTO for bulk identity resolution
 */
export class BulkResolveIdentityDto {
  @IsString()
  remoteInstanceId!: string;

  @IsArray()
  @IsString({ each: true })
  remoteUserIds!: string[];
}

/**
 * DTO for creating identity mapping
 */
export class CreateIdentityMappingDto {
  @IsString()
  remoteInstanceId!: string;

  @IsString()
  remoteUserId!: string;

  @IsString()
  oidcSubject!: string;

  @IsEmail()
  email!: string;

  @IsOptional()
  @IsObject()
  @SanitizeObject()
  metadata?: Record<string, unknown>;

  @IsOptional()
  @IsString()
  oidcToken?: string;
}

/**
 * DTO for updating identity mapping
 */
export class UpdateIdentityMappingDto {
  @IsOptional()
  @IsObject()
  @SanitizeObject()
  metadata?: Record<string, unknown>;
}
