import {
  IsString,
  IsOptional,
  IsBoolean,
  IsNumber,
  IsArray,
  IsEnum,
  MaxLength,
  IsDateString,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { ScheduleType } from '../entities/branch-schedule.entity';

class ShiftDto {
  @IsString()
  @MaxLength(50)
  name: string;

  @IsString()
  start: string;

  @IsString()
  end: string;
}

export class CreateBranchScheduleDto {
  @IsString()
  @MaxLength(100)
  name: string;

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

  @IsOptional()
  @IsEnum(['regular', 'holiday', 'special'])
  scheduleType?: ScheduleType;

  @IsOptional()
  @IsNumber()
  dayOfWeek?: number; // 0=domingo, 1=lunes, ..., 6=sabado

  @IsOptional()
  @IsDateString()
  specificDate?: string;

  @IsString()
  openTime: string;

  @IsString()
  closeTime: string;

  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => ShiftDto)
  shifts?: ShiftDto[];
}

export class UpdateBranchScheduleDto {
  @IsOptional()
  @IsString()
  @MaxLength(100)
  name?: string;

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

  @IsOptional()
  @IsEnum(['regular', 'holiday', 'special'])
  scheduleType?: ScheduleType;

  @IsOptional()
  @IsNumber()
  dayOfWeek?: number;

  @IsOptional()
  @IsDateString()
  specificDate?: string;

  @IsOptional()
  @IsString()
  openTime?: string;

  @IsOptional()
  @IsString()
  closeTime?: string;

  @IsOptional()
  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => ShiftDto)
  shifts?: ShiftDto[];

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