<?php

namespace App\Http\Requests\Admin\Manage;

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

class OrderDraftItemRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can(Permission::ORDERS_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', 'integer', 'min:1'],
            'price_type' => ['required', Rule::enum(PriceType::class)],
            'stock_quality' => ['required', Rule::enum(ProductStockQuality::class)],
        ];
    }
}
