<?php

namespace Blazemedia\OneSignal\Push;

/**
 * Notification Creator for converting CMS data to OneSignal notifications
 */
class NotificationCreator
{
    /**
     * Create notification from push notification data
     */
    public static function fromArray(array $pushData): Notification
    {
        $url = $pushData['url'] ?? '';

        return new Notification([
            'title'   => $pushData['title'] ?? '',
            'content' => $pushData['content'] ?? '',
            'url'     => $url,
            'image'   => $pushData['image'] ?? '',
        ]);
    }

    /**
     * Create notification from WordPress post
     */
    public static function fromPost(\WP_Post $post, string $imageUrl = ''): Notification
    {
        // Get the URL with UTM parameters
        $url = \get_permalink($post->ID);
        
        return self::fromArray([
            'title' => $post->post_title,
            'content' => \wp_trim_words($post->post_excerpt ?: $post->post_content, 40),
            'url'     => $url,
            'image'   => $imageUrl ?: \get_the_post_thumbnail_url($post->ID, 'medium'),
        ]);
        
    }

    /**
     * Create notification from custom data
     */
    public static function fromData(string $title, string $content, string $url = '', string $image = ''): Notification
    {
        return self::fromArray([
            'title' => $title,
            'content' => $content,
            'url' => $url,
            'image' => $image,
        ]);

    }
} 