import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsString, IsInt, IsOptional, IsEnum, Min, Max, IsArray, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
import { CombatantType, ActionType } from '../../../generated/prisma/client.js';

export class CreateCombatantAbilityDto {
  @ApiProperty({ description: 'Ability name' })
  @IsString()
  name: string;

  @ApiProperty({ description: 'Action cost (0 for free/reaction, 1-3 for actions)' })
  @IsInt()
  @Min(0)
  @Max(3)
  actionCost: number;

  @ApiProperty({ enum: ['ACTION', 'REACTION', 'FREE'] })
  @IsEnum(ActionType)
  actionType: ActionType;

  @ApiProperty({ description: 'Ability description' })
  @IsString()
  description: string;

  @ApiPropertyOptional({ description: 'Damage dice (e.g. "2d6+4 slashing")' })
  @IsOptional()
  @IsString()
  damage?: string;

  @ApiPropertyOptional({ description: 'Ability traits', type: [String] })
  @IsOptional()
  @IsArray()
  @IsString({ each: true })
  traits?: string[] = [];
}

export class CreateCombatantDto {
  @ApiProperty({ description: 'Combatant name' })
  @IsString()
  name: string;

  @ApiProperty({ enum: ['PC', 'NPC', 'MONSTER'] })
  @IsEnum(CombatantType)
  type: CombatantType;

  @ApiProperty({ description: 'Combatant level' })
  @IsInt()
  @Min(-1)
  @Max(30)
  level: number;

  @ApiProperty({ description: 'Maximum HP' })
  @IsInt()
  @Min(1)
  hpMax: number;

  @ApiProperty({ description: 'Armor Class' })
  @IsInt()
  @Min(0)
  ac: number;

  @ApiProperty({ description: 'Fortitude save modifier' })
  @IsInt()
  fortitude: number;

  @ApiProperty({ description: 'Reflex save modifier' })
  @IsInt()
  reflex: number;

  @ApiProperty({ description: 'Will save modifier' })
  @IsInt()
  will: number;

  @ApiProperty({ description: 'Perception modifier' })
  @IsInt()
  perception: number;

  @ApiPropertyOptional({ description: 'Movement speed in feet', default: 25 })
  @IsOptional()
  @IsInt()
  @Min(0)
  speed?: number = 25;

  @ApiPropertyOptional({ description: 'Avatar image URL' })
  @IsOptional()
  @IsString()
  avatarUrl?: string;

  @ApiPropertyOptional({ description: 'Description/notes' })
  @IsOptional()
  @IsString()
  description?: string;

  @ApiPropertyOptional({ description: 'Combat abilities', type: [CreateCombatantAbilityDto] })
  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CreateCombatantAbilityDto)
  abilities?: CreateCombatantAbilityDto[] = [];
}
