<?php

namespace App\Http\Controllers;

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

class AppointmentController extends Controller
{
    public function __construct(ResponseRepository $response) {
        $this->response = $response;
        $this->storeRules = [
            'patient_name' => 'required',
            'mobile_no' => 'required',
            'purpose_visit' => 'required',
            'appointment_date' => 'required',
        ];
    }

    public function show($id) {
        return $this->response->jsonResponse(false, $this->response->message('Appointment Details', 'show'), $this->findAppointment($id), 200);
    }

    public function findAppointment($id) {
        return Appointment::find($id);
    }

    public function getAppointmentDetails() {
        return $this->response->jsonResponse(false, "Appointment Details Content Fetched Successfully", Appointment::orderBy('id', 'desc')->get(), 200);
    }

    public function appointmentCreate(Request $request) {
        $validate = $this->response->validate($request->all(), $this->storeRules);
        if($validate === true) {
            return $this->response->jsonResponse(false, $this->response->message('Appointment Details', 'store'), Appointment::create($request->all()), 200);
        } else {
            return $validate;
        }
    }
}
