<?php

namespace App\Http\Requests;

use Mtc\MercuryDataModels\VehicleType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;

class BulkCreateNewCarRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return Auth::check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'franchise_id' => ['required', 'integer', 'exists:franchises,id'],
            'model_ids' => ['required', 'array', 'min:1', 'max:200'],
            'model_ids.*' => ['integer', 'distinct', 'exists:vehicle_models,id'],
            'template_id' => ['nullable', 'integer', 'exists:page_templates,id'],
            'form_id' => ['nullable', 'integer', 'exists:forms,id'],
            'test_drive_form_id' => ['nullable', 'integer', 'exists:forms,id'],
            'vehicle_type' => ['nullable', 'string', Rule::in(array_column(VehicleType::cases(), 'value'))],
        ];
    }
}
