<?php

namespace PeytzMail\Entity;

use PeytzMail\Exception\InvalidArgumentException;

/**
 * @package PeytzMail
 */
class TriggerMail extends AbstractEntity
{
    /**
     * Create the trigger mail entity from the given JSON string.
     *
     * @param  string                   $json The JSON string.
     * @throws InvalidArgumentException
     */
    public function createFromJson($json)
    {
        $data = json_decode($json);

        if (!isset($data->trigger_mail)) {
            throw new InvalidArgumentException('[Peytz Mail] We cannot create the entity with this JSON data.');
        }

        $this->build($data->trigger_mail);
    }

    /**
     * Create the trigger mail entity from the given stdClass object.
     *
     * @param \stdClass $object
     */
    public function createFromObject(\stdClass $object)
    {
        $this->build($object);
    }
}
