<?php

namespace App\Http\Controllers;

use App\Models\LanguageProficiency;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class LanguageProficiencyController extends Controller
{

    public function index()
    {
        return LanguageProficiency::all();
    }

    public function store(Request $request)
    {

        LanguageProficiency::create(
            $this->validateRequest($request)
        );

        return back(303)->with(['success' => 'success']);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    public function validateRequest(Request $request)
    {
        return $request->validate([
            'text_ar' => 'required',
            'text_en' => 'required',
        ]);
    }

    /**
     * Display the specified resource.
     *
     * @param LanguageProficiency $languageProficiency
     * @return Response
     */
    public function show(LanguageProficiency $languageProficiency)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param LanguageProficiency $languageProficiency
     * @return Response
     */
    public function edit(LanguageProficiency $languageProficiency)
    {
        //
    }

    public function update(Request $request, LanguageProficiency $languageProficiency)
    {

        $languageProficiency->update($this->validateRequest($request));

        return back(303)->with(['success' => 'success']);
    }

    public function destroy(LanguageProficiency $languageProficiency)
    {
        $languageProficiency->delete();
        return back(303)->with(['success' => 'success']);
    }
}
