<?php

final class SemiStructuredObjectInstancePHIDType extends PhabricatorPHIDType {

  const TYPECONST = 'SSIN';

  public function getTypeName() {
    return pht('Object Instance');
  }

  public function newObject() {
    return new SemiStructuredObjectInstance();
  }

  public function getPHIDTypeApplicationClass() {
    return 'SemiStructuredDataApplication';
  }

  protected function buildQueryForObjects(
    PhabricatorObjectQuery $query,
    array $phids) {

    return id(new SemiStructuredObjectInstanceQuery())
      ->withPHIDs($phids);
  }

  public function loadHandles(
    PhabricatorHandleQuery $query,
    array $handles,
    array $objects) {

    foreach ($handles as $phid => $handle) {
      $item = $objects[$phid];

      $id = $item->getID();

      $class = $item->getClass();

      $handle->setName(
        pht("%s\xE2\x96\xB9%s",
        $class->getName(),
        $item->getName()));
      $handle->setURI($item->getURI());
    }
  }

}
