<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\CIQCompany;
use Str;

class CIQCompanyController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $datas = CIQCompany::get();
        return view('Admin.ciq_company.index', compact('datas'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('Admin.ciq_company.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $validatedData = $request->validate([
            'name' => 'required | unique:c_i_q_companies',
        ]);

        $data = new CIQCompany();
        $data->name = $request->name;
        $data->slug = Str::slug($request->name);
        $data->cell_phone = $request->cell_phone;
        $data->tell_phone = $request->tell_phone;
        $data->email = $request->email;
        $data->city = $request->city;
        $data->address = $request->address;
        $data->status = $request->status;
        $data->save();

        $notification = array(
            'messege'   => 'Save Successfull',
            'alert-type' => 'success'
        );
        return redirect()->back()->with($notification);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data = CIQCompany::find($id);
        return view('Admin.ciq_company.edit', compact('data'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $data = CIQCompany::find($id);
        $data->name = $request->name;
        $data->slug = Str::slug($request->name);
        $data->cell_phone = $request->cell_phone;
        $data->tell_phone = $request->tell_phone;
        $data->email = $request->email;
        $data->city = $request->city;
        $data->address = $request->address;
        $data->status = $request->status;
        $data->save();

        $notification = array(
            'messege'   => 'Save Successfull',
            'alert-type' => 'success'
        );
        return redirect()->back()->with($notification);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $data = CIQCompany::findOrFail($id);
        $data->delete();

        $notification = array(
            'messege'   => 'Delete Successfull',
            'alert-type' => 'error'
        );
        return redirect()->back()->with($notification);
    }
}
