<?php

namespace Blazemedia\OneSignal\Push;

/**
 * Notification class for OneSignal push notifications
 */
class Notification
{
    public string $title = 'empty';
    public string $content = '';
    public string $url = '';
    public string $image = '';

    /**
     * Constructor
     */
    public function __construct(array $args = [])
    {
        foreach ($args as $key => $value) {
            if (property_exists($this, $key)) {
                $this->$key = $value;
            }
        }
    }

    /**
     * Set UTM parameters
     */
    public function setUtm(string $source = '', string $medium = '')
    {
        $vars = [];

        if ($source) $vars['utm_source'] = urlencode($source);
        if ($medium) $vars['utm_medium'] = urlencode($medium);

        $this->url = empty($vars) ? $this->url : $this->url .= '?' . http_build_query($vars);
    }

    /**
     * Get OneSignal variables
     */
    public function getOSVars()
    {
        return [
            "url" => $this->url,
            "headings" => ["en" => $this->title],
            "contents" => ["en" => $this->content],
            'big_picture' => $this->image,
            'chrome_web_image' => $this->image,
            'ios_attachments' => ['id' => $this->image]
        ];
    }
} 