<?php

namespace PloverCRM\Modules\PushNotifications\Services;

use PloverCRM\Common\BaseLogger;

/**
 * Push Notifications Logger
 * 
 * Handles logging for push notification operations
 */
class Logger extends BaseLogger
{
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct(
            'push-notifications',
            'push-notifications',
            'push-notifications',
            [
                'module' => 'notifications',
                'feature' => 'notifications',
            ]
        );
    }

    /**
     * Log notification sent successfully
     * 
     * @param object $subscriber subscriber object
     * @return void
     */
    public function logNotificationSent($subscriber): void
    {
        $name = trim(($subscriber['first_name'] ?? '') . ' ' . ($subscriber['last_name'] ?? ''));
        $location = array_filter([$subscriber['city'] ?? '', $subscriber['country'] ?? '']);

        $this->logInfo('Push notification sent successfully', [
            'subscriber_id' => $subscriber['id'],
            'subscriber_email' => $subscriber['email'],
            'subscriber_name' => $name ?: 'N/A',
            'location' => !empty($location) ? implode(', ', $location) : 'N/A',
            'created_at' => $subscriber['created_at'] ?? '',
        ]);
    }

    /**
     * Log notification error
     * 
     * @param object $subscriber subscriber object
     * @param string $error Error message
     * @return void
     */
    public function logNotificationError($subscriber, string $error): void
    {
        $name = trim(($subscriber['first_name'] ?? '') . ' ' . ($subscriber['last_name'] ?? ''));

        $this->logError('Failed to send push notification', [
            'subscriber_id' => $subscriber['id'],
            'subscriber_email' => $subscriber['email'],
            'subscriber_name' => $name ?: 'N/A',
            'error' => $error,
        ]);
    }
}
