<?php
namespace MiotApi\Contract\Instance;
use MiotApi\Contract\Specification\ServiceSpecification;
use MiotApi\Contract\Specification\Specification;
use MiotApi\Contract\Urn;
use MiotApi\Util\Collection\Collection;
class Service extends Specification
{
protected $data;
protected $propertiesNode;
protected $iid;
protected $specification;
public function __construct($data = [])
{
$this->data = $data;
$this->init();
}
public function init()
{
$this->collection = new Collection($this->data);
$this->iid = $this->collection->get('iid');
$this->urn = new Urn($this->collection->get('type'));
$this->specification = new ServiceSpecification($this->urn->getBaseUrn());
$this->initProperties();
}
protected function initProperties()
{
if ($this->has('properties')) {
$properties = $this->get('properties');
if (!empty($properties)) {
foreach ($properties as $property) {
$this->propertiesNode[$property['iid']] = new Property($property);
}
}
}
}
public function getIid()
{
return $this->iid;
}
public function property($piid)
{
return $this->propertiesNode[$piid];
}
public function getPropertiesNode()
{
return $this->propertiesNode;
}
public function getSpecification()
{
return $this->specification;
}
public function getSpecificationContext()
{
return $this->specification->toContext();
}
}