<?php

namespace App\Http\Requests\Billing;

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

class UpdateBillingRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->isAdmin() ?? false;
    }

    /**
     * @return array<string, ValidationRule|array<int, mixed>|string>
     */
    public function rules(): array
    {
        return [
            'jumlah_credit' => ['required', 'integer', 'min:1'],
            'rate' => ['required', 'integer', 'min:1'],
            'bank_id' => ['nullable', Rule::exists('banks', 'id')],
            'user_id' => ['required', Rule::exists('users', 'id')],
            'payment_method' => ['nullable', 'string', 'in:manual,duitku'],
        ];
    }
}
