<?php

namespace App\Http\Requests\Admin\Manage;

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

class CuttingQuickCreateProductRequest extends FormRequest
{
    use HasProductVariantRules;

    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'],
            'description' => ['nullable', 'string'],

            'category_ids' => ['nullable', 'array'],
            'category_ids.*' => ['integer', Rule::exists('categories', 'id')->whereNull('deleted_at')],

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

    /**
     * @return array<string, string>
     */
    public function attributes(): array
    {
        return [
            'name' => 'Nama Produk',
            'description' => 'Deskripsi',
            'category_ids' => 'Kategori',
            'category_ids.*' => 'Kategori',
            ...$this->productVariantAttributes(),
        ];
    }
}
