<?php

namespace App\Http\Requests\Admin\Manage;

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

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

    public function rules(): array
    {
        return [
            'opname_date' => ['required', 'date'],
            'items' => ['required', 'array', 'min:1'],
            'items.*.product_variant_id' => ['required', 'integer', Rule::exists('product_variants', 'id')],
            'items.*.stock_quality' => ['required', Rule::in(ProductStockQuality::values())],
            'items.*.physical_stock' => ['required', 'integer', 'min:0'],
            'notes' => ['nullable', 'string', 'max:100'],
        ];
    }

    public function attributes(): array
    {
        return [
            'opname_date' => 'Tanggal Opname',
            'items' => 'Item produk',
            'items.*.product_variant_id' => 'Varian produk',
            'items.*.stock_quality' => 'Jenis stok',
            'items.*.physical_stock' => 'Stok fisik',
            'notes' => 'Keterangan',
        ];
    }
}
