/**
 * Connection DTOs
 *
 * Data Transfer Objects for federation connection API.
 */

import { IsString, IsUrl, IsOptional, IsObject, IsNumber, ValidateNested } from "class-validator";
import { Type } from "class-transformer";
import { Sanitize, SanitizeObject } from "../../common/decorators/sanitize.decorator";
import { FederationCapabilitiesDto } from "./capabilities.dto";

/**
 * DTO for initiating a connection
 */
export class InitiateConnectionDto {
  @IsUrl()
  remoteUrl!: string;
}

/**
 * DTO for accepting a connection
 */
export class AcceptConnectionDto {
  @IsOptional()
  @IsObject()
  @SanitizeObject()
  metadata?: Record<string, unknown>;
}

/**
 * DTO for rejecting a connection
 */
export class RejectConnectionDto {
  @IsString()
  @Sanitize()
  reason!: string;
}

/**
 * DTO for disconnecting a connection
 */
export class DisconnectConnectionDto {
  @IsOptional()
  @IsString()
  @Sanitize()
  reason?: string;
}

/**
 * DTO for incoming connection request (from remote instance)
 */
export class IncomingConnectionRequestDto {
  @IsString()
  instanceId!: string;

  @IsUrl()
  instanceUrl!: string;

  @IsString()
  publicKey!: string;

  @ValidateNested()
  @Type(() => FederationCapabilitiesDto)
  capabilities!: FederationCapabilitiesDto;

  @IsNumber()
  timestamp!: number;

  @IsString()
  signature!: string;
}
