<?php

namespace Modules\Language\Repositories;

use Illuminate\Http\Request;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Language\Interfaces\LanguageRepositoryInterface;
use Modules\Language\Models\Language;
use Modules\Language\Models\LanguageDescription;

class LanguageRepository implements LanguageRepositoryInterface
{
    public function get(array $request)
    {
        $builder = Language::query();
        return $builder;
    }

    public function getItem(int $id)
    {
        return Language::find($id);
    }

    public function checkItem(int $id)
    {
        return Language::find($id);
    }

    public function getItemTrashed(int $id)
    {
        $language = Language::onlyTrashed()->find($id);
        return $language ;
    }

    public function create(array $request): Language
    {
        $language = Language::create($request);
        return $language;
    }

    public function update(array $request, ?Language $language): Language
    {
        $language->update($request);

        return $language;
    }

    /**
     * Remove the specified Language from storage.
     * @param Language $language
     * @return void
     */
    public function destroy(Language $language) :void
    {
        $language->delete();
    }

    /**
     * Remove several languages by IDs.
     *
     * @param array $request
     * @return void
     */
    public function destroyAll(array $ids) :void
    {
         Language::whereIn('id', $ids)->delete();
    }

    /**
     * Restore the specified language from storage.
     *
     * @param Language $language
     * @return void
     */
    public function restore(Language $language) :void
    {
        $language->restore();
    }

    /**
     * Restore several languages by IDs.
     *
     * @param array $request
     * @return void
     */
    public function restoreAll(array $ids) :void
    {
        Language::whereIn('id', $ids)->onlyTrashed()->restore();
    }
}
