<?php
declare(strict_types = 1);

namespace App\Http\Controllers\Registration;

use App\Exceptions\GeneralException;
use App\Http\Logics\Registration\RegisterLogic;
use App\Http\Requests\Registration\RegisterRequest;
use App\Http\Resources\Registration\Record\RecordListsResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class RegisterController
{
    protected RegisterLogic $register_logic;

    /**
     * Patient Construct.
     */
    public function __construct()
    {
        $this->register_logic = new RegisterLogic();
    }

    /**
     * 获取挂号记录列表
     * @param RegisterRequest $request
     * @param string $patient_id 此处为 patient_number
     * @return JsonResponse
     * @throws GeneralException
     */
    public function register(RegisterRequest $request, string $patient_id): JsonResponse
    {
        $validated = $request->safe()->only(['date', 'dept_id', 'doctor_id', 'reg_id']);

        $response = $this->register_logic->register($patient_id, $validated['date'], $validated['dept_id'], $validated['doctor_id'], $validated['reg_id']);

        return jsonResponse(Response::HTTP_OK, 'success', $response);
    }
}