import { IsString, IsNotEmpty, IsOptional, IsNumber, IsArray, IsDateString, ValidateNested } from 'class-validator'
import { Type } from 'class-transformer'

export class InvoiceLineItemDto {
  @IsString() @IsNotEmpty()
  description: string

  @IsNumber()
  quantity: number

  @IsNumber()
  unitPrice: number

  @IsNumber()
  amount: number

  @IsOptional() @IsArray() @IsString({ each: true })
  timeEntryIds?: string[]
}

export class CreateInvoiceDto {
  @IsString() @IsNotEmpty()
  clientFolderId: string

  @IsOptional() @IsString()
  matterId?: string

  @IsArray() @ValidateNested({ each: true }) @Type(() => InvoiceLineItemDto)
  lineItems: InvoiceLineItemDto[]

  @IsNumber()
  subtotal: number

  @IsOptional() @IsNumber()
  vatRate?: number

  @IsNumber()
  vatAmount: number

  @IsNumber()
  total: number

  @IsOptional() @IsString()
  currency?: string

  @IsDateString()
  issueDate: Date

  @IsDateString()
  dueDate: Date

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

  @IsString() @IsNotEmpty()
  createdBy: string
}
