<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class StoreRouletteItemRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('roulette.manage');
    }

    public function rules(): array
    {
        // The legacy `create_item_roulette`/`save_item_roulette` actions
        // never validated weight/value_min/value_max as numeric at all —
        // any string was accepted and fed straight into mt_rand().
        return [
            'roulette_category_id' => ['required', 'exists:roulette_categories,id'],
            'name' => ['required', 'string', 'max:100'],
            'image' => [$this->isMethod('post') ? 'required' : 'nullable', 'image', 'max:2048'],
            'weight' => ['required', 'integer', 'min:1', 'max:100000'],
            'value_min' => ['required', 'integer', 'min:0'],
            'value_max' => ['required', 'integer', 'gte:value_min'],
        ];
    }
}
