<?php

namespace App\Http\Requests\Dashboard\UsefulInfoItemRequest;

use Illuminate\Foundation\Http\FormRequest;

class Store extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name_uz' => 'required|string',
            'name_ru' => 'required|string',
            'description_uz' => 'nullable|string',
            'description_ru' => 'nullable|string',
            'video_url' => 'nullable|string',
            'link_url' => 'nullable|string',
            'file' => 'nullable|file|mimes:pdf,doc,docx,xls,xlsx,ppt,pptx',
        ];
    }

    /**
     * @return array
     */
    public function getName(): array|null
    {
        if ($this->has('name_uz') && $this->has('name_ru')) {
            return [
                'uz' => $this->get('name_uz'),
                'ru' => $this->get('name_ru')
            ];
        }

        return null;
    }

    public function getDescription(): array|null
    {
        if ($this->get('description_uz') !== null && $this->get('description_ru') !== null) {
            return [
                'uz' => $this->get('description_uz'),
                'ru' => $this->get('description_ru')
            ];
        }

        return null;
    }
}
