<?php

namespace App\Http\Controllers;

use App\Models\TestSessionsModel;
use Illuminate\Http\Request;

class TestSessionsController extends Controller
{
    public function getScreen(Request $request) {
        $data = TestSessionsModel::where('id_test_sessions', $request->id_test_sessions)->first();

        if($data != null) {
            return response()->json([
                'status' => true,
                'screen_w' => $data->screen_w,
                'screen_h' => $data->screen_h
            ]);
        } else {
            return response()->json([
                'status' => false,
                'msg' => 'Data tidak ditemukan!'
            ]);
        }
    }
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $request->validate([
            'id_booking' => 'required|exists:booking,id_booking',
        ]);

        $testSession = TestSessionsModel::create([
            'id_booking' => $request->id_booking,
            'status_session' => '0',
            'is_active' => '0',
            'screen_w' => $request->screen_w,
            'screen_h' => $request->screen_h
        ]);

        return redirect()->route('tutorial-tes.index')->with([
            'id_booking' => $testSession->id_booking,
            'id_test_sessions' => $testSession->id_test_sessions,
            'token_session' => $testSession->token_session,
        ]);
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        $data = TestSessionsModel::where('id_booking', $id)->first();
        if($data != null) {
            return response()->json([
                'status' => true,
                'msg' => 'Data ditemukan (' . $id . ')',
                'status_session' => $data->status_session,
                'token_session' => $data->token_session,
                'id_booking' => $data->id_booking,
                'id_test_sessions' => $data->id_test_sessions,
            ]);

        }
        return response()->json([
            'status' => false,
            'msg' => 'Data tidak ditemukan (' . $id . ')',
        ]);
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        //
    }
}
