<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

/**
 * Fired after an expense record is created.
 * Lets the Dashboard refresh its expense totals in real-time.
 */
class ExpenseCreated implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function __construct(
        public readonly int    $organizationId,
        public readonly ?int   $branchId,
        public readonly int    $expenseId,
        public readonly string $expenseNumber,
        public readonly float  $amount,
        public readonly string $category,
    ) {}

    public function broadcastOn(): array
    {
        return [new PrivateChannel("org.{$this->organizationId}")];
    }

    public function broadcastAs(): string
    {
        return 'expense.created';
    }
}
