import {
  IsUUID,
  IsString,
  IsDateString,
  IsNumber,
  IsInt,
  IsOptional,
  IsEnum,
  IsBoolean,
  MinLength,
} from 'class-validator';
import { VendorType } from '../entities/vendor.entity';
import { AcquisitionType, AcquisitionStatus } from '../entities/asset-acquisition.entity';
import { DisposalMethod } from '../entities/asset-disposal.entity';

export class CreateVendorDto {
  @IsString()
  name!: string;

  @IsOptional()
  @IsEnum(VendorType)
  type?: VendorType;

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

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

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

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

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

export class UpdateVendorDto {
  @IsOptional()
  @IsString()
  name?: string;

  @IsOptional()
  @IsEnum(VendorType)
  type?: VendorType;

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

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

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

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

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

export class CreateAcquisitionDto {
  /** WHAT was acquired — required so an acquisition can't be saved empty. */
  @IsString()
  @MinLength(2)
  itemName!: string;

  @IsOptional()
  @IsUUID()
  vehicleId?: string;

  @IsOptional()
  @IsUUID()
  vendorId?: string;

  @IsEnum(AcquisitionType)
  acquisitionType!: AcquisitionType;

  @IsDateString()
  acquisitionDate!: string;

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

  @IsOptional()
  @IsInt()
  usefulLifeMonths?: number;

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

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

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

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

  @IsOptional()
  @IsEnum(AcquisitionStatus)
  status?: AcquisitionStatus;

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

export class UpdateAcquisitionDto {
  @IsOptional()
  @IsString()
  @MinLength(2)
  itemName?: string;

  @IsOptional()
  @IsUUID()
  vehicleId?: string;

  @IsOptional()
  @IsUUID()
  vendorId?: string;

  @IsOptional()
  @IsEnum(AcquisitionType)
  acquisitionType?: AcquisitionType;

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

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

  @IsOptional()
  @IsInt()
  usefulLifeMonths?: number;

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

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

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

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

  @IsOptional()
  @IsEnum(AcquisitionStatus)
  status?: AcquisitionStatus;

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

export class CreateDisposalDto {
  @IsUUID()
  vehicleId!: string;

  @IsDateString()
  disposalDate!: string;

  @IsEnum(DisposalMethod)
  method!: DisposalMethod;

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

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

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