<?php

namespace App\Modules\Settings\Localization\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreTranslationRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('translations.create') ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'key' => [
                'required', 'string', 'max:255',
                Rule::unique('translations', 'key')->where(fn ($q) => $q->where('locale', $this->input('locale'))),
            ],
            'group' => ['nullable', 'string', 'max:100'],
            'locale' => ['required', 'string', 'max:10', 'exists:languages,code'],
            'value' => ['required', 'string'],
        ];
    }
}
