import {
  IsNumber,
  IsBoolean,
  IsOptional,
  IsDateString,
  Min,
  Max,
  ValidateNested,
  IsInt,
  IsString,
  MaxLength
} from 'class-validator';
import { Type } from 'class-transformer';

class FeedbackCategories {
  @IsOptional()
  @IsNumber()
  @Min(1, { message: 'Clarity rating must be between 1 and 10' })
  @Max(10, { message: 'Clarity rating must be between 1 and 10' })
  clarity?: number;

  @IsOptional()
  @IsNumber()
  @Min(1, { message: 'Pace rating must be between 1 and 10' })
  @Max(10, { message: 'Pace rating must be between 1 and 10' })
  pace?: number;

  @IsOptional()
  @IsNumber()
  @Min(1, { message: 'Interaction rating must be between 1 and 10' })
  @Max(10, { message: 'Interaction rating must be between 1 and 10' })
  interaction?: number;

  @IsOptional()
  @IsNumber()
  @Min(1, { message: 'Materials rating must be between 1 and 10' })
  @Max(10, { message: 'Materials rating must be between 1 and 10' })
  materials?: number;

  @IsOptional()
  @IsNumber()
  @Min(1, { message: 'Atmosphere rating must be between 1 and 10' })
  @Max(10, { message: 'Atmosphere rating must be between 1 and 10' })
  atmosphere?: number;
}

export class CreateFeedbackDto {
  @Type(() => Number)
  @IsInt({ message: 'Student ID must be an integer' })
  studentId: number;

  @Type(() => Number)
  @IsInt({ message: 'Teacher ID must be an integer' })
  teacherId: number;

  @Type(() => Number)
  @IsInt({ message: 'Lesson ID must be an integer' })
  lessonId: number;

  @IsDateString({}, { message: 'Lesson date must be a valid ISO 8601 date string' })
  lessonDate: Date;

  @Type(() => Number)
  @IsNumber()
  @Min(1, { message: 'Overall rating must be between 1 and 10' })
  @Max(10, { message: 'Overall rating must be between 1 and 10' })
  overallRating: number;

  @IsOptional()
  @ValidateNested()
  @Type(() => FeedbackCategories)
  categories?: FeedbackCategories;

  @IsOptional()
  @IsString()
  @MaxLength(2000, { message: 'What was good text cannot exceed 2000 characters' })
  whatWasGood?: string;

  @IsOptional()
  @IsString()
  @MaxLength(2000, { message: 'What can improve text cannot exceed 2000 characters' })
  whatCanImprove?: string;

  @IsOptional()
  @IsString()
  @MaxLength(2000, { message: 'Additional comments cannot exceed 2000 characters' })
  additionalComments?: string;

  @IsOptional()
  @IsBoolean()
  isAnonymous?: boolean;

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