<?php

namespace App\Http\Requests\Admin\Finance;

use App\Concerns\CurrencyStripping;
use Illuminate\Foundation\Http\FormRequest;
use Override;

class CashTransactionRequest extends FormRequest
{
    use CurrencyStripping;

    public function authorize(): bool
    {
        return $this->user()->can('cash.deposit')
            || $this->user()->can('cash.withdraw');
    }

    #[Override]
    public function prepareForValidation(): void
    {
        $this->merge($this->stripCurrencyDot($this->all(), 'amount'));
    }

    public function rules(): array
    {
        return [
            'amount' => ['required', 'integer', 'min:1'],
            'description' => ['required', 'string', 'max:100'],
            'receipt_key' => ['required', 'string', 'max:500'],
            'file_size' => ['nullable', 'integer', 'min:1'],
            'file_mime_type' => ['nullable', 'string', 'in:image/jpeg,image/png,image/webp,image/gif'],
        ];
    }

    public function attributes(): array
    {
        return [
            'amount' => 'jumlah',
            'description' => 'keterangan',
            'receipt_key' => 'bukti',
            'file_size' => 'ukuran file',
            'file_mime_type' => 'tipe file',
        ];
    }
}
