<?php

namespace App\Http\Requests\Admin\Manage;

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

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

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