import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsString,
  IsOptional,
  IsInt,
  IsBoolean,
  IsUUID,
  IsDateString,
  Min,
  Max,
  IsArray,
} from 'class-validator';
import { Type } from 'class-transformer';

export class CreateGroupEventDto {
  @ApiProperty()
  @IsUUID()
  serviceId: string;

  @ApiProperty()
  @IsUUID()
  staffId: string;

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

  @ApiPropertyOptional({ example: 'Утренняя йога' })
  @IsString()
  @IsOptional()
  title?: string;

  @ApiProperty({ example: '2026-03-15T09:00:00Z' })
  @IsDateString()
  startAt: string;

  @ApiProperty({ example: '2026-03-15T10:00:00Z' })
  @IsDateString()
  endAt: string;

  @ApiProperty({ description: 'Max participants', example: 20 })
  @IsInt()
  @Min(1)
  @Max(1000)
  @Type(() => Number)
  capacity: number;
}

export class UpdateGroupEventDto {
  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  staffId?: string;

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

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

  @ApiPropertyOptional()
  @IsDateString()
  @IsOptional()
  startAt?: string;

  @ApiPropertyOptional()
  @IsDateString()
  @IsOptional()
  endAt?: string;

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

export class RepeatGroupEventDto {
  @ApiProperty({ description: 'Days of week to repeat (0=Mon..6=Sun)', example: [0, 2, 4] })
  @IsArray()
  @IsInt({ each: true })
  daysOfWeek: number[];

  @ApiProperty({ description: 'Repeat until date', example: '2026-06-30' })
  @IsDateString()
  repeatUntil: string;

  @ApiPropertyOptional({ description: 'Skip notifications', default: true })
  @IsBoolean()
  @IsOptional()
  skipNotifications?: boolean;
}

export class FindGroupEventsQueryDto {
  @ApiPropertyOptional()
  @IsUUID()
  @IsOptional()
  serviceId?: string;

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

  @ApiPropertyOptional({ example: '2026-03-01' })
  @IsDateString()
  @IsOptional()
  from?: string;

  @ApiPropertyOptional({ example: '2026-03-31' })
  @IsDateString()
  @IsOptional()
  to?: string;

  @ApiPropertyOptional({ description: 'Include cancelled events', default: false })
  @IsBoolean()
  @IsOptional()
  @Type(() => Boolean)
  includeCancelled?: boolean;
}
