<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ProviderBankAccountStoreRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'bank_id'             => ['required_without:bank_code', 'nullable', 'integer', Rule::exists('banks', 'id')->where('active', true)->whereNull('deleted_at')],
            'bank_code'           => ['required_without:bank_id', 'nullable', 'string', 'max:3'],
            'type'                => ['required', Rule::in(['checking', 'savings'])],
            'branch_number'       => ['required', 'string', 'max:4'],
            'branch_check_digit'  => ['sometimes', 'nullable', 'string', 'max:2'],
            'account_number'      => ['required', 'string', 'max:13'],
            'account_check_digit' => ['required', 'string', 'max:2'],
        ];
    }
}
