File "CreatePaymentRequest.php"

Full Path: /var/www/html/back/app/Domain/Payment/Requests/CreatePaymentRequest.php
File size: 2.64 KB
MIME-type: text/x-php
Charset: utf-8

<?php

declare(strict_types=1);

namespace App\Domain\Payment\Requests;

use App\BaseClasses\BaseApiRequest;
use App\Domain\Payment\Enums\PaymentStatusEnum;
use App\Domain\Payment\Enums\PaymentTypeEnum;

class CreatePaymentRequest extends BaseApiRequest
{
    public function rules(): array
    {
        return [
            'name' => ['bail', 'required', 'string'],
            //'status' => ['bail', 'required', 'string'],
            'payment_type' => ['bail', 'required', 'string'],
            'payment_date' => ['bail', 'nullable', 'date_format:Y-m-d'],
            'amount' => [
                'bail', 'required', 'numeric', 'regex:/^\d+(\.\d{1,2})?$/', 'max:999999999999.99'
            ],
            'files' => ['bail', 'nullable', 'array'],
            'counterparty_id' => ['bail', 'nullable', 'integer', 'exists:counterparties,id'],
            'account_id' => ['bail', 'nullable', 'integer', 'exists:accounts,id'],
            'organization_id' => ['bail', 'nullable', 'integer', 'exists:organizations,id'],
            'files.*' => [
                'bail', 'nullable', 'string'
            ],
            'distributions' => ['nullable', 'array']
        ];
    }

    public static function bodyParameters(): array
    {
        return [
            'name' => ['description' => 'name'],
            //'status' => ['description' => 'status'],
            'payment_type' => ['description' => 'type'],
            'payment_date' => ['description' => 'date'],
            'files.*' => ['description' => 'files'],
            'amount' => ['description' => 'amount'],
            'contragent_id' => ['description' => 'contragent_id'],
            'account_id' => ['description' => 'account_id'],
            'project_id' => ['description' => 'project_id'],
            'article_id' => ['description' => 'article_id'],
            'files' => ['description' => 'ID файлов'],
            'distributions' => ['description' => 'payment_distribution'],
        ];
    }

    public static function example(): array
    {
        return [
            'name' => 'Тестовый платеж',
            //'status' => PaymentStatusEnum::STATUS_DRAFT->value,
            'payment_type' => PaymentTypeEnum::PAYMENT_TYPE_PAYMENT->value,
            'payment_date' => '2022-01-01',
            'amount' => 1000,
            'contragent_id' => 1,
            'account_id' => 1,
            'files' => ['1','2','3','4'],
            'project_id' => 1,
            'article_id' => 1,
            'distributions' => [
                ['project_id' => 1, 'article_id' => 2, 'amount' => 1000],
                ['project_id' => 2, 'article_id' => 3, 'amount' => 2000]
            ]
        ];
    }
}