<?php

namespace App\Http\Requests\Api\Dashboard\Admin\WorkoutCategory;

use App\Http\Requests\Api\ApiMasterRequest;
use Illuminate\Validation\Rule;

class WorkoutCategoryRequest extends ApiMasterRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        $rules = [];
        foreach (config('translatable.locales') as $locale) {
            $rules[$locale . '.title']        = [
                'required',
                'between:3,250',
                Rule::unique('workout_category_translations', 'title')->where(function ($query) use ($locale) {
                    return $query->where('locale', $locale)->where('workout_category_id', '!=', $this->workout_category);
                })
            ];
        }
        return $rules;
    }
}
