<?php

namespace App\Http\Requests\Api\V1\Product\Review;

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

class ProductReviewStore extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'rating' => ['required', 'numeric', 'max:5'],
            'title' => ['required', 'string', 'max:255'],
            'content' => ['nullable', 'string', 'max:255'],
            'source' => ['required', 'string', Rule::in(array_keys(OS::apps()))],
        ];
    }

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