<?php

namespace App\Http\Requests\Admin\Manage;

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

class CuttingDraftResultRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can(Permission::CUTTINGS_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'),
            ],
            'cutting_result' => ['required', 'integer', 'min:1'],
            'sample' => ['required', 'integer', 'min:0'],
            'original_outside_sample' => ['required', 'integer', 'min:0'],
        ];
    }
}
