<?php

namespace Modules\Lpj\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class TeamsRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $rules = [
            'name'              => 'required|string|max:255',
            'status'            => 'nullable|boolean',
            'regions_id'         => 'required|nullable|exists:regions,id',
            'user.*'            => 'nullable|exists:users,id',
            'authorized_at'     => 'nullable|datetime',
            'authorized_status' => 'nullable|string|max:1',
            'authorized_by'     => 'nullable|exists:users,id',

        ];

        if ($this->method() == 'PUT') {
            $rules['code'] = 'required|string|max:3|unique:teams,code,' . $this->id;
        } else {
            $rules['code'] = 'required|string|max:3|unique:teams,code';
        }

        return $rules;
    }

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }
}
