<?php

namespace App\Http\Requests\Admin\Manage;

use App\Enums\Permission;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PurchaseDraftItemRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can(Permission::PURCHASES_CREATE->value) ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'raw_material_price_id' => [
                'required',
                'integer',
                Rule::exists('raw_material_prices', 'id')->whereNull('deleted_at'),
            ],
            'quantity' => ['required', 'numeric', 'decimal:0,4', 'gt:0'],
        ];
    }
}
