<?php

namespace App\Jobs;

use App\Models\MessageModel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public $uuid;
    public $nama_setting_siaga;
    public $pesan;
    public $uuid_contact;
    public $uuid_device;
    public $uuid_group;
    public $siaga;
    
    public function __construct($uuid,$nama_setting_siaga,$pesan,$uuid_contact,$uuid_device,$uuid_group,$siaga)
    {
        $this->uuid = $uuid;
        $this->nama_setting_siaga = $nama_setting_siaga;
        $this->pesan = $pesan;
        $this->uuid_contact = $uuid_contact;
        $this->uuid_device = $uuid_device;
        $this->uuid_group = $uuid_group;
        $this->siaga = $siaga;
    }
    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $message = new MessageModel();
        $message->uuid_device_results = $this->uuid;
        $message->title = $this->nama_setting_siaga;
        $message->message = $this->pesan;
        $message->date_time = now();
        $message->send_by = "Otomatis";
        $message->uuid_user = $this->uuid_contact;
        $message->siaga = $this->siaga;
        $message->uuid_device = $this->uuid_device;
        $message->uuid_group = $this->uuid_group;
        $message->save();
        return $message;
    }
}
