<?php

namespace App\Http\Requests\Api\System\VersionManagement;

use App\Models\System\Settings\OS;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CheckForUpdateRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
     */
    public function rules(): array
    {
        return [
            'version' => ['required', 'string', 'max:255'],
            'os' => ['required', 'string', 'max:255', Rule::in(array_keys(OS::apps()))],
        ];
    }

    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'os.in' => sprintf('Valid sources: %s', implode(', ', array_keys(OS::apps()))),
        ];
    }
}
