<?php
/**
 * Event Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Events
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Events;


use BplanBase\Globals\Broadcasting\ChannelNames;
use BplanBase\Globals\Models\PrintJob;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;


/**
 * Event Class
 *
 * Wird gefeuert, wenn der PrinService einen Fehler per Callback gemeldet hat
 * oder wenn die Callback-Verarbeitung intern fehlschlug.
 *
 * @version     1.0.0 / 2026-04-27
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class PrintJobFailed implements ShouldBroadcast
{


/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    use Dispatchable, InteractsWithSockets, SerializesModels;


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * @param       PrintJob $PrintJob
     *
     * @version     1.0.0 / 2026-04-27
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function __construct(public readonly PrintJob $PrintJob) {}


    /**
     * @return      string
     *
     * @version     1.0.0 / 2026-05-04
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function broadcastAs(): string
    {
        return 'print-job.failed';

    } // broadcastAs()


    /**
     * @return      Channel[]
     *
     * @version     1.0.0 / 2026-05-04
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function broadcastOn(): array
    {
        return [
            new PrivateChannel(ChannelNames::printJob($this->PrintJob->uuid)),
        ];

    } // broadcastOn()


    /**
     * @return      array<string, mixed>
     *
     * @version     1.0.0 / 2026-05-04
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function broadcastWith(): array
    {
        return [
            'error_message' => $this->PrintJob->error_message,
            'status'        => $this->PrintJob->status->value,
            'uuid'          => $this->PrintJob->uuid,
        ];

    } // broadcastWith()


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


} // class PrintJobFailed {}
