<?php

final class ExtensionStorePublisherEditEngine
  extends ExtensionStoreEditEngine {

  const ENGINECONST = 'est:publisher';

  public function getEngineName() {
    return pht('Publisher');
  }

  public function getSummaryHeader() {
    return pht('Edit Publisher');
  }

  public function getSummaryText() {
    return pht('This engine is used to modify extension publishers.');
  }

  protected function newEditableObject() {
    $viewer = $this->getViewer();
    return ExtensionStorePublisher::initializeNewPublisher($viewer);
  }

  protected function newObjectQuery() {
    return new ExtensionStorePublisherQuery();
  }

  protected function getObjectCreateTitleText($object) {
    return pht('Create Publisher');
  }

  protected function getObjectCreateButtonText($object) {
    return pht('Create Publisher');
  }

  protected function getObjectCreateCancelURI($object) {
    return $this->getApplication()->getApplicationURI('publisher/');
  }

  protected function getEditorURI() {
    return $this->getApplication()->getApplicationURI('publisher/edit/');
  }

  protected function getObjectEditTitleText($object) {
    return pht('Edit Publisher: %s', $object->getName());
  }

  protected function getObjectEditShortText($object) {
    return pht('Edit Publisher');
  }

  protected function getObjectCreateShortText() {
    return pht('Create Publisher');
  }

  protected function getObjectName() {
    return pht('Publisher');
  }

  protected function getObjectViewURI($object) {
    return $object->getURI();
  }

  protected function buildCustomEditFields($object) {

    $fields = array();

    $fields[] = new PhabricatorTextEditField()
        ->setKey('name')
        ->setLabel(pht('Name'))
        ->setDescription(pht('Name of the publisher.'))
        ->setConduitDescription(pht('Rename the publisher.'))
        ->setConduitTypeDescription(pht('New publisher name.'))
        ->setTransactionType(
          ExtensionStorePublisherNameTransaction::TRANSACTIONTYPE)
        ->setIsRequired(true)
        ->setValue($object->getName());

    if ($this->getIsCreate()) {
      $fields[] = id(new PhabricatorTextEditField())
        ->setKey('publisherKey')
        ->setLabel(pht('Publisher Key'))
        ->setDescription(pht('Unique key to identify the publisher.'))
        ->setTransactionType(
          ExtensionStorePublisherKeyTransaction::TRANSACTIONTYPE)
        ->setIsRequired(true)
        ->setValue($object->getPublisherKey());
    }

    $fields[] = new PhabricatorRemarkupEditField()
        ->setKey('description')
        ->setLabel(pht('Description'))
        ->setDescription(pht('Publisher long description.'))
        ->setConduitTypeDescription(pht('Free-text description.'))
        ->setTransactionType(
          ExtensionStorePublisherDescriptionTransaction::TRANSACTIONTYPE)
        ->setValue($object->getDescription());

    return $fields;
  }

}
