<?php

namespace Magetop\Agency\Model;

use Magetop\Agency\Api\Data\DataInterface;
use Magento\Framework\DataObject\IdentityInterface;

class Data extends \Magento\Framework\Model\AbstractModel implements DataInterface, IdentityInterface
{
    /**
     * No route page id.
     */
    const NOROUTE_ENTITY_ID = 'no-route';

    /**
     * Assign Product Data cache tag.
     */
    const CACHE_TAG = 'assignproduct_data';

    /**
     * @var string
     */
    protected $_cacheTag = 'assignproduct_data';

    /**
     * Prefix of model events names.
     *
     * @var string
     */
    protected $_eventPrefix = 'assignproduct_data';

    /**
     * Initialize resource model.
     */
    protected function _construct()
    {
        $this->_init('Magetop\Agency\Model\ResourceModel\Data');
    }

    /**
     * Load object data.
     *
     * @param int|null $id
     * @param string   $field
     *
     * @return $this
     */
    public function load($id, $field = null)
    {
        if ($id === null) {
            return $this->noRoutePreorder();
        }

        return parent::load($id, $field);
    }

    /**
     * Load No-Route Quote.
     *
     * @return \Magetop\Agency\Model\Data
     */
    public function noRouteQuote()
    {
        return $this->load(self::NOROUTE_ENTITY_ID, $this->getIdFieldName());
    }

    /**
     * Get identities.
     *
     * @return array
     */
    public function getIdentities()
    {
        return [self::CACHE_TAG.'_'.$this->getId()];
    }

    /**
     * Get ID.
     *
     * @return int
     */
    public function getId()
    {
        return parent::getData(self::ENTITY_ID);
    }

    /**
     * Set ID.
     *
     * @param int $id
     *
     * @return \Magetop\Agency\Api\Data\DataInterface
     */
    public function setId($id)
    {
        return $this->setData(self::ENTITY_ID, $id);
    }
}
