import { IsString, IsNotEmpty, IsOptional, IsNumber, IsBoolean, IsEnum, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

class ActivityConfigDto {
  @ApiPropertyOptional()
  @IsOptional()
  @IsNumber()
  firstOrderRate?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsNumber()
  secondOrderRate?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsNumber()
  minCashback?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsNumber()
  maxCashback?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsNumber()
  withdrawThreshold?: number;

  @ApiPropertyOptional()
  @IsOptional()
  @IsNumber()
  maxOrderIndex?: number;
}

export class CreateActivityDto {
  @ApiProperty()
  @IsString()
  @IsNotEmpty()
  name: string;

  @ApiProperty({ enum: ['invite_cashback'] })
  @IsEnum(['invite_cashback'])
  type: 'invite_cashback';

  @ApiPropertyOptional()
  @IsOptional()
  @IsBoolean()
  enabled?: boolean;

  @ApiPropertyOptional({ type: () => ActivityConfigDto })
  @IsOptional()
  @ValidateNested()
  @Type(() => ActivityConfigDto)
  config?: ActivityConfigDto;
}

export class UpdateActivityDto {
  @ApiPropertyOptional()
  @IsOptional()
  @IsString()
  name?: string;

  @ApiPropertyOptional()
  @IsOptional()
  @IsBoolean()
  enabled?: boolean;

  @ApiPropertyOptional({ type: () => ActivityConfigDto })
  @IsOptional()
  @ValidateNested()
  @Type(() => ActivityConfigDto)
  config?: ActivityConfigDto;
}

export class QueryActivityDto {
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @IsOptional()
  @Type(() => Number)
  pageSize?: number = 10;

  @IsOptional()
  @IsEnum(['invite_cashback'])
  type?: 'invite_cashback';

  @IsOptional()
  @IsBoolean()
  @Type(() => Boolean)
  enabled?: boolean;
}

export class RejectInviteWithdrawalDto {
  @IsString()
  @IsNotEmpty()
  reason: string;
}

export class QueryAdminInviteWithdrawalsDto {
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @IsOptional()
  @Type(() => Number)
  pageSize?: number = 20;

  @IsOptional()
  @IsEnum(['pending', 'approved', 'rejected', 'paid'])
  status?: 'pending' | 'approved' | 'rejected' | 'paid';
}

export class QueryAdminCashbacksDto {
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @IsOptional()
  @Type(() => Number)
  pageSize?: number = 20;
}

export class QueryInviteRecordsDto {
  @IsOptional()
  @Type(() => Number)
  page?: number = 1;

  @IsOptional()
  @Type(() => Number)
  pageSize?: number = 20;
}
