import { Type } from 'class-transformer';
import {
  IsDateString,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  IsUUID,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';
import { CashHolderDto } from './cash-holder.dto';

/** Fields shared by every Cash Held action. */
abstract class CashHeldActionBaseDto {
  @ValidateNested()
  @Type(() => CashHolderDto)
  holder: CashHolderDto;

  @IsUUID()
  currency_id: string;

  @IsNumber({ maxDecimalPlaces: 2 })
  @Min(0.01)
  amount: number;

  @IsDateString()
  date: string;
}

/** B — cash given to / spent for a customer of a booking. */
export class CashHeldCustomerUseDto extends CashHeldActionBaseDto {
  @IsUUID()
  booking_id: string;

  // Purpose is required (validated here, not inherited as optional).
  @IsString()
  @IsNotEmpty()
  @MaxLength(2000)
  notes: string;
}

/** C — cash handed from one holder to another. */
export class CashHeldTransferDto extends CashHeldActionBaseDto {
  @ValidateNested()
  @Type(() => CashHolderDto)
  to_holder: CashHolderDto;

  @IsOptional()
  @IsString()
  @MaxLength(2000)
  notes?: string;
}

/** D — cash returned to the office bank. */
export class CashHeldReturnDto extends CashHeldActionBaseDto {
  @IsUUID()
  bank_account_id: string;

  @IsOptional()
  @IsString()
  @MaxLength(100)
  ref_no?: string;

  @IsOptional()
  @IsString()
  @MaxLength(2000)
  notes?: string;
}
