// eslint-disable-next-line max-classes-per-file import { ApiProperty } from '@nestjs/swagger'; import { ExpenseItemFromType } from '@prisma/client'; import { Type } from 'class-transformer'; import { IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested, } from 'class-validator'; import { IsISODateTimeString } from '../../../../shared/validators'; class ExpensePaymentDto { @ApiProperty({ description: 'Способ оплаты', example: 'CASH', enum: ExpenseItemFromType, }) @IsString() @IsNotEmpty({ message: 'Способ оплаты обязателен к заполнению' }) @IsEnum(ExpenseItemFromType) type: ExpenseItemFromType; @ApiProperty({ description: 'ID карты или наличных ', example: '123', type: String, }) @IsString() @IsNotEmpty({ message: 'ID источника оплаты обязателен к заполнению' }) id: string; } export class CreateExpenseListItemDto { @ApiProperty({ description: 'Заголовок расхода', example: 'Кофе', type: String, }) @IsString({ message: 'Заголовок расхода должен быть строкой.' }) @IsNotEmpty({ message: 'Заголовок расхода обязателен к заполнению.' }) title: string; @ApiProperty({ description: 'Описание', example: 'Перед работой', type: String, nullable: true, }) @IsOptional() @IsString({ message: 'Описание расхода должно быть строкой.' }) description?: string; @ApiProperty({ description: 'Дата', example: '2025-08-22T04:12:03.726Z', type: Date, }) @IsNotEmpty({ message: 'Дата расхода обязателен к заполнению.' }) @IsISODateTimeString({ message: 'Дата должна быть строкой в формате ISO 8601' }) date: Date; @ApiProperty({ description: 'Сумма расхода', example: 175.50, type: Number, }) @IsNotEmpty({ message: 'Сумма расхода обязательна к заполнению.' }) @IsNumber({ allowInfinity: false, allowNaN: false, maxDecimalPlaces: 2 }, { message: 'Сумма расхода должна быть числом.' }) amount: number; @ApiProperty({ description: 'Валюта расхода', example: 'RUB', type: String, default: 'RUB', nullable: true, }) @IsOptional() @IsString({ message: 'Валюта расхода должна быть строкой.' }) currency?: string; @ApiProperty({ description: 'Количество', example: 2, type: Number, default: 1, nullable: true, }) @IsOptional() @IsNumber({ allowInfinity: false, allowNaN: false, maxDecimalPlaces: 2 }, { message: 'Количество должно быть числом.' }) count?: number; @ApiProperty({ description: 'Оплата', type: ExpensePaymentDto, nullable: true, }) @IsOptional() @ValidateNested() @Type(() => ExpensePaymentDto) payment?: ExpensePaymentDto; }