<?php


namespace App\Libs\Push\HuaWei\Admin\Msg\Notification;


use Exception;

class Notification
{
    /**
     * optional
     */
    private $title;

    /**
     * optional
     */
    private $body;

    /**
     * optional
     */
    private $image;

    private $fields;

    public function __construct($title, $body, $image)
    {
        $this->title  = $title;
        $this->body   = $body;
        $this->image  = $image;
        $this->fields = array();
    }

    public function title($value)
    {
        $this->title = $value;
    }

    public function body($value)
    {
        $this->body = $value;
    }

    public function image($value)
    {
        $this->image = $value;
    }

    public function getFields()
    {
        return $this->fields;
    }

    public function buildFields()
    {
        try {
            $this->check_parameter();
        } catch (Exception $e) {
            echo $e;
        }
        $keys = array(
            'title',
            'body',
            'image'
        );
        foreach ($keys as $key) {
            if (isset($this->$key)) {
                $this->fields[$key] = $this->$key;
            }
        }
    }

    private function check_parameter()
    {
        if (empty($this->title)) {
            throw new Exception("title should be set");
        }
        if (empty($this->body)) {
            throw new Exception("body should be set");
        }
    }
}