<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CartItemRequest extends FormRequest
{
    public function rules(): array
    {
        $rules = [
            'cart_id'     => ['sometimes', 'integer', 'exists:carts,id'],
            'schedule_id' => ['sometimes', 'integer', 'exists:schedules,id'],
        ];

        if ($this->isMethod('POST')) {
            $rules['cart_id']     = ['required', 'integer', 'exists:carts,id'];
            $rules['schedule_id'] = ['required', 'integer', 'exists:schedules,id'];
        }

        return $rules;
    }

    /**
    * Add custom messages when needed
    * public function messages(): array
    * {
    *   return [
    *        'field.required' => __('message.algo'),
    *    ];
    * }
    */
}
