<?php

namespace App\Listeners;

use App\Events\ParcelCollected;
use App\Services\SlackNotifierService;
use App\Services\TrelloService;
use Illuminate\Support\Facades\Log;

class NotifySlackOnParcelCollected
{
    public function __construct(
        protected SlackNotifierService $slack,
        protected TrelloService $trello,
    ) {
    }

    public function handle(ParcelCollected $event): void
    {
        $order = $event->order;
        $message = "📤 Parcel collected: Order #{$order->order_number}\n" .
            "Tracking: {$order->courier_tracking_number}";

        $this->slack->shipping($message);

        Log::info('Parcel collected notification sent', ['order_uuid' => $order->uuid]);

        if ($order->trello_card_id) {
            $this->trello->moveCard($order->trello_card_id, 'In Transit');
        }
    }
}
