<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:50', 'alpha_dash'],
            'label' => ['required', 'string', 'max:100'],
            'grades' => ['nullable', 'array'],
            'grades.*.name' => ['required_with:grades', 'string', 'max:50'],
            'grades.*.label' => ['required_with:grades', 'string', 'max:100'],
            'grades.*.level' => ['required_with:grades', 'integer', 'min:0'],
            'grades.*.salary' => ['required_with:grades', 'integer', 'min:0'],
        ];
    }
}
