<?php

namespace App\Http\Requests\Admin\Master\RawMaterial;

use App\Concerns\CurrencyStripping;
use Illuminate\Foundation\Http\FormRequest;

class RawMaterialVariantRequest extends FormRequest
{
    use CurrencyStripping;

    public function authorize(): bool
    {
        return $this->user()->can('raw_materials.create')
            || $this->user()->can('raw_materials.update');
    }

    public function prepareForValidation(): void
    {
        $this->merge($this->stripCurrencyDot($this->all(), 'price'));
    }

    public function rules(): array
    {
        return [
            'variant' => ['required', 'string', 'max:200'],
            'price' => ['required', 'integer', 'min:0'],
            'stock' => ['required', 'integer', 'min:0'],
            'photo_key' => ['required', 'string', 'max:500'],
        ];
    }

    public function attributes(): array
    {
        return [
            'variant' => 'nama varian',
            'price' => 'harga',
            'stock' => 'stok',
            'photo_key' => 'foto',
        ];
    }
}
