<?php

namespace App\Http\Requests\Admin\Manage;

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

class RestockRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('restocks.create')
            || $this->user()->can('restocks.update');
    }

    public function rules(): array
    {
        return [
            'stock_type' => ['sometimes', 'required', Rule::in(ProductStockQuality::values())],
            'items' => ['required', 'array', 'min:1'],
            'items.*.product_variant_id' => ['required', 'integer', Rule::exists('product_variants', 'id')],
            'items.*.quantity' => ['required', 'integer', 'min:1'],
            'notes' => ['nullable', 'string', 'max:100'],
            'photo_key' => ['nullable', 'string', 'max:500'],
        ];
    }

    public function attributes(): array
    {
        return [
            'stock_type' => 'jenis stok',
            'items' => 'item produk',
            'items.*.product_variant_id' => 'varian produk',
            'items.*.quantity' => 'jumlah',
            'notes' => 'keterangan',
            'photo_key' => 'foto',
        ];
    }
}
