<?php

namespace App\Helpers;

use Illuminate\Support\Carbon;
use MacsiDigital\Zoom\Facades\Zoom;

class ZoomHelper
{
    public static function createMeeting($topic)
    {
        $meeting = Zoom::meeting()->make([
            'topic' => $topic,
            'type' => 8,
            'start_time' => Carbon::now()->format('Y-m-d h:i:s'), // best to use a Carbon instance here.
        ]);

        $meeting->recurrence()->make([
            'type' => 2,
            'repeat_interval' => 1,
            'weekly_days' => '2',
            'end_times' => 1
        ]);

        $meeting->settings()->make([
            'join_before_host' => false,
            'approval_type' => 1,
            'registration_type' => 2,
            'enforce_login' => false,
            'waiting_room' => true,
            'host_video' => false,
            "participant_video" => false,
            "mute_upon_entry" => true,
            "auto_recording" => "none",

        ]);

        $user = Zoom::user()->first();

        $user->meetings()->save($meeting);

        return $meeting;

    }

    public static function deleteMeeting($meetingId)
    {
        $meeting = Zoom::meeting()->find($meetingId);
        if ($meeting->id){
            $meeting->endMeeting();
//            $meeting->delete();
            return true;
        }
        return false;
    }
}
