<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\AdmissionInput;
use Illuminate\Support\Facades\Log;
use App\Repositories\ResponseRepository;

class AdmissionInputController extends Controller
{

    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'kid_name' => 'required',
            'father_name' => 'required',
            'mother_name' => 'required',
            'mobile' => 'required',

            'date_of_birth' => 'required',
            // 'courses_id' => 'required',
            'courses_name' => 'required',
            'date' => 'required',
            // 'time_id' => 'required',
            'time' => 'required',
            'description' => 'required',

        ];
    }

    
    public function show($id) {
        return $this->response->jsonResponse(false, $this->response->message('Admission Us Details', 'show'), $this->findAdmissionInput($id), 500);
    }

    public function findAdmissionInput($id) {
        return AdmissionInput::find($id);
    }
    public function admissionInputCreate(Request $request) {
        Log::info('request =='. $request);
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            return $this->response->jsonResponse(false, 'Your Details Successfully Updated', AdmissionInput::create($request->all()), 502);
        } else {
            return $validate;
        }
    }

    public function getAdmissionDetailsadmin() {
        return $this->response->jsonResponse(false, $this->response->message('Admission Us Details', 'index'), AdmissionInput::orderBy('id', 'desc')->get(), 501);
    }

    public function searchadmissionsinput($search){
        if($search === "null") {
            return $this->response->jsonResponse(false, $this->response->message('Admission', 'search'), [], 110);
        }
        return $this->response->jsonResponse(false, $this->response->message('Admission', 'search'), AdmissionInput::where('kid_name', 'LIKE', '%'.$search.'%')->get(), 504);
    }
    public function searchAboutBanner($search){
        if($search === "null") {
            return $this->response->jsonResponse(false, $this->response->message('Banner', 'search'), [], 110);
        }
        return $this->response->jsonResponse(false, $this->response->message('Banner', 'search'), AboutBanner::where('banner_name', 'LIKE', '%'.$search.'%')->get(), 111);
    }

}
