<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\curriculamDetail;
use App\Repositories\ResponseRepository;
use Illuminate\Support\Facades\Log;
class curriculamDetailController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'courses_id' => 'required',
            'courses_name' => 'required',
            'curriculam_title' => 'required',
            // 'curriculam_description' => 'required',
            'play_sub_title' => 'required',
            'play_sub_description' => 'required',
            'play_bullet_one' => 'required',
            'play_bullet_two' => 'required',
            'play_bullet_three' => 'required',
            'play_bullet_four' => 'required',
            // 'play_para' => 'required',
        ];
    }

    public function indexcurriculamDetail() {
        return $this->response->jsonResponse(false, "Curriculam Details  Fetched Successfully", curriculamDetail::with('courseslist')->orderBy('curriculam_detail_id', 'desc')->get() , 300);
    }

    public function store(Request $request) {
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            $request['courses_slug'] = $this->response->generateSlug($request['courses_name']);
            return $this->response->jsonResponse(false, $this->response->message('curriculamDetail', 'store'), curriculamDetail::create($request->all()), 301);
        } else {
            return $validate;
        }
    }

    public function show($id) {
        return $this->response->jsonResponse(false, $this->response->message('curriculam Detail', 'show'), $this->findBanner($id), 102);
    }

    public function destroy($id) {
        $size = $this->findBanner($id);
        if($size) {
            return $this->response->jsonResponse(false, $this->response->message('curriculam Detail', 'destroy'), $size->delete(), 104);
        }
        return $this->response->jsonResponse(true, 'curriculam Detail Not Exists', [], 105);
    }

     public function findBanner($id) {
        return curriculamDetail::find($id);
    }

    public function updatecurriculamDetail(Request $request) {
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {

            $request['courses_slug'] = $this->response->generateSlug($request['courses_name']);
            return $this->response->jsonResponse(false, $this->response->message('curriculam Detail', 'update'), $this->findBanner($request->id)->update($request->all()), 303);
        } else {
            return $validate;
        }
    }

    public function curriculamDetailSwitch($id) {
        $size = $this->findBanner($id);
        if($size) {
            $value = $size->active_status === 1 ? 0 : 1;
            $msg = $value === 0 ? 'Deactivated': 'Activated';
            return $this->response->jsonResponse(false, 'Banner '.$msg.' SuccessFully', $size->update(['active_status' => $value]), 106);
        }
        return $this->response->jsonResponse(true, 'curriculam Detail Not Exists', [], 107);
    }

    public function searchcurriculamDetail($search){
        if($search === "null") {
            return $this->response->jsonResponse(false, $this->response->message('curriculam Detail', 'search'), [], 110);
        }
        return $this->response->jsonResponse(false, $this->response->message('curriculam Detail', 'search'), curriculamDetail::where('curriculam_title', 'LIKE', '%'.$search.'%')->get(), 111);
    }

}
