<?php

namespace App\Listeners\Mobile;

use App\Events\Mobile\DeclinedTimesheetEvent;
use App\Models\ProjectWorkerTimesheet;

class DeclineTimesheetListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(DeclinedTimesheetEvent $event)
    {
        // Commented because the model used by the previous developer is not existing anymore, unfinished work 

        // $timesheet = ProjectWorkerTimesheet::select(
        //     'project_worker_timesheet.*',
        //     'assigned_workers.project_id'
        // )
        //     ->join('assigned_workers', 'assigned_worker.id', 'project_worker_timeshet.project_worker_id')
        //     ->where('project_worker_timesheet.id', $event->timesheet)
        //     ->first();

        // $decline_notification = [
        //     "project_id" => $timesheet->project_id,
        //     "worker_id" => $timesheet->worker_id,
        //     "timesheet_id" => $timesheet->id,
        //     "message" => "Your timehseet for " . $timesheet->date . " have been declined by " . $timesheet->requested_by,
        //     "date" => Carbon::now(),
        //     'is_read' => false,
        // ];

        // $timesheet_notification = TimehseetNotification::create($decline_notification);

        // event(new TimesheetEvent(['new_notif' => true, 'data' => $timesheet_notification, 'type' => 'timesheet']));
    }
}
