122 lines
2.9 KiB
PHP
122 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\ProntoAtendimento\Plantao;
|
|
|
|
use App\Enums\ProntoAtendimento\Plantao\TipoEscala;
|
|
use App\Http\Requests\FormRequest;
|
|
use App\Models\ProntoAtendimento\Plantao\Status;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class PlantaoRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
switch ($this->method()) {
|
|
|
|
case 'POST': {
|
|
|
|
return $this->getPostRules();
|
|
}
|
|
case 'PATCH': {
|
|
|
|
return $this->getPatchRules();
|
|
}
|
|
default: {
|
|
|
|
return [];
|
|
}
|
|
}
|
|
}
|
|
|
|
private function getPostRules()
|
|
{
|
|
return [
|
|
'lotacao_id' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'servico_id' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'faixa_etaria_id' => [
|
|
'nullable',
|
|
'integer'
|
|
],
|
|
'escala.tipo_id' => [
|
|
'required',
|
|
'integer',
|
|
],
|
|
'escala.inicio' => [
|
|
'required',
|
|
'date',
|
|
],
|
|
'escala.fim' => [
|
|
'required',
|
|
'date',
|
|
'after:escala.inicio',
|
|
],
|
|
'escala.dias_semana' => [
|
|
'required_if:escala.tipo_id,' . TipoEscala::FIXA,
|
|
'array',
|
|
],
|
|
'escala.dias_semana.*' => [
|
|
'integer',
|
|
'between:1,7'
|
|
],
|
|
'escala.jornada_em_horas' => [
|
|
'required_if:escala_tipo_id,' . TipoEscala::FIXA . ',' . TipoEscala::DINAMICA,
|
|
'integer',
|
|
Rule::in([6, 8, 12, 24])
|
|
],
|
|
'escala.quantidade_atendimentos' => [
|
|
'required',
|
|
'integer',
|
|
'max:99999999',
|
|
],
|
|
'status_id' => [
|
|
'nullable',
|
|
'integer',
|
|
Rule::exists(Status::class, 'id'),
|
|
],
|
|
];
|
|
}
|
|
|
|
private function getPatchRules()
|
|
{
|
|
return [
|
|
'status_id' => [
|
|
'integer'
|
|
],
|
|
'escala.inicio' => [
|
|
'required_with:escala.fim',
|
|
'date',
|
|
],
|
|
'escala.fim' => [
|
|
'required_with:escala.inicio',
|
|
'date',
|
|
'after:escala.inicio',
|
|
],
|
|
'escala.quantidade_atendimentos' => [
|
|
'integer',
|
|
'max:99999999',
|
|
],
|
|
];
|
|
}
|
|
}
|