<?php

namespace App\Http\Requests\Admin\Manage;

use App\Enums\Permission;
use App\Enums\RawMaterialUnit;
use App\Http\Requests\Concerns\HasRawMaterialPriceRules;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CuttingQuickCreateRawMaterialRequest extends FormRequest
{
    use HasRawMaterialPriceRules;

    public function authorize(): bool
    {
        return $this->user()?->can(Permission::CUTTINGS_CREATE->value) ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:200'],
            'unit' => ['required', Rule::enum(RawMaterialUnit::class)],

            ...$this->rawMaterialPriceRules(),
        ];
    }

    /**
     * @return array<string, string>
     */
    public function attributes(): array
    {
        return [
            'name' => 'Nama Bahan Baku',
            'unit' => 'Satuan',
            ...$this->rawMaterialPriceAttributes(),
        ];
    }
}
