<?php

final class SemiStructuredInstanceConfiguredCustomField
  extends SemiStructuredInstanceCustomField
  implements PhabricatorStandardCustomFieldInterface {

  public function getStandardCustomFieldNamespace() {
    return 'semistruct.instance';
  }

  public function createFields($instance) {

    // TODO assert SemiStructuredObjectInstance

    if ($instance->hasAttachedClass()) {
      $class = $instance->getClass();
      $config = $class->getCustomFieldsConfig();
    } else {
      $config = array();
    }

    return PhabricatorStandardCustomField::buildStandardFields($this, $config);
  }

  public function newStorageObject() {
    return new SemiStructuredInstanceConfiguredCustomFieldStorage();
  }

  protected function newStringIndexStorage() {
    return new SemiStructuredInstanceCustomFieldStringIndex();
  }

  protected function newNumericIndexStorage() {
    return new SemiStructuredInstanceCustomFieldNumericIndex();
  }

}
