<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use App\Services\TwilioService;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use App\Models\ClinicIdentity;
use App\Helper\Helper;

class SendWhatsAppNotification implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $patient;
    protected $appointment;

    public function __construct($appointment)
    {
        $this->patient = $appointment->patient()->first();
        $this->appointment = $appointment;
    }

    public function handle(TwilioService $twilio)
    {
        $twilio->sendWhatsAppMessage($this->patient->phone, $this->getMessage());
    }

    public function getMessage()
    {
       return Helper::buildMessageAppointmentWhatsApp($this->appointment);
    }
}