import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsInt,
  IsBoolean,
  IsEnum,
  IsNumber,
  IsUUID,
  Min,
  Max,
} from 'class-validator';
import { Type } from 'class-transformer';
import { BookingServiceType } from '@prisma/client';

export class CreateBookingServiceDto {
  @ApiProperty({ example: 'Персональная тренировка' })
  @IsString()
  @IsNotEmpty()
  name: string;

  @ApiPropertyOptional()
  @IsString()
  @IsOptional()
  description?: string;

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  categoryId?: string;

  @ApiProperty({ description: 'Duration in minutes', example: 60 })
  @IsInt()
  @Min(5)
  @Max(480)
  @Type(() => Number)
  duration: number;

  @ApiPropertyOptional({ description: 'Buffer before (minutes)', default: 0 })
  @IsInt()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  bufferBefore?: number;

  @ApiPropertyOptional({ description: 'Buffer after (minutes)', default: 0 })
  @IsInt()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  bufferAfter?: number;

  @ApiPropertyOptional({ example: 3000 })
  @IsNumber()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  price?: number;

  @ApiPropertyOptional({ enum: BookingServiceType, default: 'INDIVIDUAL' })
  @IsEnum(BookingServiceType)
  @IsOptional()
  type?: BookingServiceType;

  @ApiPropertyOptional({ description: 'Max participants (GROUP only)', example: 20 })
  @IsInt()
  @Min(1)
  @IsOptional()
  @Type(() => Number)
  capacity?: number;

  @ApiPropertyOptional({ description: 'Extra places per participant', default: 0 })
  @IsInt()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  extraPlaces?: number;

  @ApiPropertyOptional({ default: true })
  @IsBoolean()
  @IsOptional()
  isOnline?: boolean;

  @ApiPropertyOptional({ default: false })
  @IsBoolean()
  @IsOptional()
  membershipOnly?: boolean;

  @ApiPropertyOptional({ description: 'HEX color', example: '#3B82F6' })
  @IsString()
  @IsOptional()
  color?: string;

  @ApiPropertyOptional({ description: 'Staff IDs who can provide this service' })
  @IsUUID('4', { each: true })
  @IsOptional()
  staffIds?: string[];
}

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

  @ApiPropertyOptional()
  @IsString()
  @IsOptional()
  description?: string;

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  categoryId?: string;

  @ApiPropertyOptional()
  @IsInt()
  @Min(5)
  @Max(480)
  @IsOptional()
  @Type(() => Number)
  duration?: number;

  @ApiPropertyOptional()
  @IsInt()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  bufferBefore?: number;

  @ApiPropertyOptional()
  @IsInt()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  bufferAfter?: number;

  @ApiPropertyOptional()
  @IsNumber()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  price?: number;

  @ApiPropertyOptional({ enum: BookingServiceType })
  @IsEnum(BookingServiceType)
  @IsOptional()
  type?: BookingServiceType;

  @ApiPropertyOptional()
  @IsInt()
  @Min(1)
  @IsOptional()
  @Type(() => Number)
  capacity?: number;

  @ApiPropertyOptional()
  @IsInt()
  @Min(0)
  @IsOptional()
  @Type(() => Number)
  extraPlaces?: number;

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

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

  @ApiPropertyOptional()
  @IsString()
  @IsOptional()
  color?: string;

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

  @ApiPropertyOptional()
  @IsUUID('4', { each: true })
  @IsOptional()
  staffIds?: string[];
}

export class CreateServiceCategoryDto {
  @ApiProperty({ example: 'Групповые занятия' })
  @IsString()
  @IsNotEmpty()
  name: string;

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  parentId?: string;
}

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

  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  parentId?: string;

  @ApiPropertyOptional()
  @IsBoolean()
  @IsOptional()
  isActive?: boolean;
}

export class ReorderServicesDto {
  @ApiProperty({ description: 'Ordered service IDs' })
  @IsUUID('4', { each: true })
  serviceIds: string[];
}
