import { ProviderPaymentStatus } from "@edr/types";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsIn, IsOptional, IsString } from "class-validator";

export type PaymentPlatformDto = "web" | "mobile";

export class InitiatePaymentDto {
  @ApiProperty({ example: "booking-uuid" })
  @IsString()
  bookingId!: string;

  @ApiProperty({ enum: ["TELEBIRR"], example: "TELEBIRR" })
  @IsIn(["TELEBIRR"])
  method!: "TELEBIRR";

  @ApiPropertyOptional({ enum: ["web", "mobile"], default: "web" })
  @IsOptional()
  @IsIn(["web", "mobile"])
  platform?: PaymentPlatformDto;
}

export class ClientActionDto {
  @ApiProperty({ enum: ["REDIRECT", "LAUNCH_APP"] })
  type!: "REDIRECT" | "LAUNCH_APP";

  @ApiPropertyOptional({ description: "Set when type=REDIRECT (web flow)" })
  url?: string;

  @ApiPropertyOptional({ description: "Set when type=LAUNCH_APP (mobile flow)" })
  appId?: string;

  @ApiPropertyOptional({ description: "Set when type=LAUNCH_APP (mobile flow)" })
  receiveCode?: string;

  @ApiPropertyOptional({ description: "Set when type=LAUNCH_APP (mobile flow)" })
  shortCode?: string;
}

export class InitiateResponseDto {
  @ApiProperty()
  intentId!: string;

  @ApiProperty({ enum: ProviderPaymentStatus })
  status!: ProviderPaymentStatus;

  @ApiPropertyOptional({ type: ClientActionDto })
  clientAction?: ClientActionDto;

  @ApiPropertyOptional()
  merchantOrderId?: string;
}

export class IntentStatusDto extends InitiateResponseDto {
  @ApiPropertyOptional()
  paidAt?: string;

  @ApiPropertyOptional()
  failureCode?: string;

  @ApiPropertyOptional()
  failureMessage?: string;
}
