<?php

namespace Modules\Inventory\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Modules\Accounts\Enums\AccountTypeEnum;
use Modules\Core\Traits\FailedValidation;
use Modules\Core\Enums\StatusEnum;

class SupplierRequest extends FormRequest
{
    use FailedValidation;

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'name' => 'required|string|max:255',
            'phone' => 'nullable|string|max:20',
            'address' => 'nullable|string',
            'account_id' => [
                'required',
                Rule::exists('chart_of_accounts', 'id')
                    ->where(
                        fn($q) => $q
                            ->where('is_group', false)
                            ->where('account_type', AccountTypeEnum::LIABILITY->value)
                    ),
            ],
            'status' => [
                'nullable',
                'string',
                Rule::enum(StatusEnum::class),
            ],
        ];
    }
}
