import {
  IsArray,
  IsBoolean,
  IsInt,
  IsISO8601,
  IsNumber,
  IsOptional,
  IsString,
  Matches,
  Min,
} from 'class-validator';

export class CheckInDto {
  @IsInt()
  studentId: number;

  @IsInt()
  roomId: number;

  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  checkInDate: string; // YYYY-MM-DD

  @IsOptional()
  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  billingStartDate?: string; // 默认=checkInDate，可调整

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

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

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

  @IsOptional()
  @IsNumber()
  @Min(0.01)
  depositAmount?: number;

  @IsInt()
  bedId: number;

  @IsOptional()
  @IsInt()
  lockerId?: number;
}

export class CheckOutDto {
  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  checkOutDate: string;

  @IsOptional()
  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  billingEndDate?: string; // 默认=checkOutDate

  @IsOptional()
  @IsString()
  checkOutReason?: string;
}

export class TransferRoomDto {
  @IsInt()
  newRoomId: number;

  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  transferDate: string; // YYYY-MM-DD

  @IsOptional()
  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  oldBillingEndDate?: string; // 旧房计费截止日，默认=transferDate

  @IsInt()
  newBedId: number;

  @IsOptional()
  @IsInt()
  newLockerId?: number;
  @IsOptional()
  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  newBillingStartDate?: string; // 新房计费起始日，默认=transferDate次日

  @IsOptional()
  @IsString()
  reason?: string;
}

export class BatchCheckOutDto {
  @IsArray()
  ids: number[];

  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  checkOutDate: string; // YYYY-MM-DD

  @IsOptional()
  @Matches(/^\d{4}-\d{2}-\d{2}$/)
  @IsISO8601({ strict: true })
  billingEndDate?: string; // 默认=checkOutDate

  @IsOptional()
  @IsString()
  checkOutReason?: string;
}
