<?php

namespace App\Http\Requests\Tenancy\Visit;

use Illuminate\Database\Query\Builder;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CreateVisitRequest 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<string, mixed>
     */
    public function rules()
    {
        return [
            'visits' => [
                'required',
                'array',
            ],
            'visits.*.procedure_id' => [
                'required',
                Rule::exists('procedures', 'id')->where(function (Builder $query) {
                    return $query->where('online', 1);
                }),
            ],
            'visits.*.date' => [
                'required',
                'date_format:Y-m-d H:i',
                'after_or_equal:now',
            ],
            'visits.*.specialist_id' => [
                'required',
                'exists:employees,id',
            ],
            'send_email' => [
                'sometimes',
                'boolean',
            ],
            'send_sms' => [
                'sometimes',
                'boolean',
            ],
            'paid_amount' => [
                'required',
                'integer',
            ],
            'sms_url' => [
                'sometimes',
                'url'
            ]
        ];
    }
}
