import {
    IsString, IsBoolean, IsOptional,
    IsArray, IsUUID, ValidateNested, IsNumberString,
    IsEnum,
    MinLength
} from 'class-validator'
import { Type } from 'class-transformer'
import { CreateTransactionItemDto } from './create-transaction-item.dto'
import { TransactionStatus } from 'generated/prisma/enums'

export class CreateTransactionDto {
    @IsUUID()
    branchId: string

    @IsUUID()
    customerId: string

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

    @IsOptional()
    @IsBoolean()
    knowsFounder?: boolean

    @IsOptional()
    @IsUUID()
    bankId?: string

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

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

    @IsOptional()
    @IsArray()
    @IsUUID('4', { each: true })
    serahTerimaIds?: string[]

    @IsOptional()
    @IsArray()
    @IsUUID('4', { each: true })
    suratPernyataanIds?: string[]

    @IsOptional()
    @IsString()
    @MinLength(10, { message: 'Please provide a more detailed reason' })
    reason?: string;

    @IsOptional()
    @IsEnum(TransactionStatus)
    status?: TransactionStatus = TransactionStatus.OPEN

    @IsArray()
    @ValidateNested({ each: true })
    @Type(() => CreateTransactionItemDto)
    items: CreateTransactionItemDto[]
}