<?php


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


use App\Libs\Push\HuaWei\Admin\Constants;
use App\Libs\Push\HuaWei\Admin\PushLogConfig;

class Alert
{
    private $title;
    private $body;
    private $title_loc_key;
    private $title_loc_args;
    private $action_loc_key;
    private $loc_key;
    private $loc_args;
    private $launch_image;

    private $fields;

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

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

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

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

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

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

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

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

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

    public function buildFields()
    {
        $keys = array(
            'title',
            'body',
            'title-loc-key',
            'title-loc-args',
            'action-loc-key',
            'loc-key',
            'loc-args',
            'launch-image'
        );
        foreach ($keys as $key) {

            $value = str_replace('-', '_', $key);

            PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][before key:' . $key . '][after key:' . $value . ']', Constants::HW_PUSH_LOG_DEBUG_LEVEL);
            if (isset($this->$value)) {
                $this->fields[$key] = $this->$value;
            }
        }
        PushLogConfig::getSingleInstance()->LogMessage('[' . __CLASS__ . '][buildFields result:' . json_encode($this->fields), Constants::HW_PUSH_LOG_DEBUG_LEVEL);

    }
}