<?php

namespace App\Http\Controllers;

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

class CourseController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->ruleOne = [
            'course_title' => 'required',
            'course_description' => 'required',
            'activites_title' => 'required',
            'activites_description' => 'required',
            'check_title' => 'required',
        ];
    }

    public function getCourseDetailsTitles() {
        return $this->response->jsonResponse(false, "Course Details  Fetched Successfully", Course::all(), 550);
    }

    public function updateCourseDetailsTitles(Request $request) {
        $validate = $this->response->validate($request->all(), $this->ruleOne);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Course Details', 'update'), Course::first()->update($request->all()), 551);
        } else {
            return $this->response->jsonResponse(true, 'Course Details Update Failed', $validate, 552);
        }
    }
}
