<?php

final class ExtensionsStoreApplication extends PhabricatorApplication {


  public function getName() {
    return pht('Extension Store');
  }

  public function getShortDescription() {
    return pht('TODO.');
  }

  public function getIcon() {
    return 'fa-battery-4';
  }

  public function getBaseURI() {
    return '/extensionstore/';
  }


  protected function getCustomCapabilities() {
    return array(
      PhabricatorPackagesCreatePublisherCapability::CAPABILITY => array(
        'default' => PhabricatorPolicies::POLICY_ADMIN,
      ),
      PhabricatorPackagesPublisherDefaultEditCapability::CAPABILITY => array(
        'caption' => pht('Default edit policy for newly created publishers.'),
        'template' => PhabricatorPackagesPublisherPHIDType::TYPECONST,
        'default' => PhabricatorPolicies::POLICY_NOONE,
      ),
      PhabricatorPackagesPackageDefaultViewCapability::CAPABILITY => array(
        'caption' => pht('Default edit policy for newly created extension.'),
        'template' => PhabricatorPackagesPackagePHIDType::TYPECONST,
      ),
      PhabricatorPackagesPackageDefaultEditCapability::CAPABILITY => array(
        'caption' => pht('Default view policy for newly created extension.'),
        'template' => PhabricatorPackagesPackagePHIDType::TYPECONST,
        'default' => PhabricatorPolicies::POLICY_NOONE,
      ),
    );
  }

  public function getRoutes() {
    return array(
        '/extensionstore/' => array(
          '' => 'ExtensionStoreHomeController',

          'publisher/' => array(
            '(?P<publisherKey>[^/]+)/' => array(
              '' => ExtensionStorePublisherManageController::class,
              'new/' => ExtensionStorePublisherNewPackageController::class,
            ),
            // TODO by publisher-key
            $this->getQueryRoutePattern() =>
              'ExtensionStorePublisherListController',
            $this->getEditRoutePattern('edit/') =>
              ExtensionStorePublisherEditController::class,
          ),
          'extension/' => array(
            $this->getQueryRoutePattern() =>
              'ExtensionStoreExtensionListController',
            $this->getEditRoutePattern('edit/') =>
              'ExtensionStoreExtensionEditController',
            'publish/(?:(?P<extensionId>\d+)/)?' =>
              ExtensionStoreExtensionNewReleaseController::class,
            '(?:(?P<id>\d+)/)?' =>
              ExtensionStoreExtensionManageController::class,
            'release/' => array(
              $this->getEditRoutePattern('edit/') =>
                ExtensionStoreReleaseEditController::class,
            ),
          ),
          'view/' => $this->getStoreRoutes(),

          /*
      '/package/' => array(
        '(?P<publisherKey>[^/]+)/' => array(
          '' => 'PhabricatorPackagesPublisherViewController',
          '(?P<packageKey>[^/]+)/' => array(
            '' => 'PhabricatorPackagesPackageViewController',
            '(?P<versionKey>[^/]+)/' =>
              'PhabricatorPackagesVersionViewController',
          ),
        ),
      ),
      '/packages/' => array(
        '' => 'PhabricatorPackagesConsoleController',

        'package/' => array(
          $this->getQueryRoutePattern() =>
            'PhabricatorPackagesPackageListController',
          $this->getEditRoutePattern('edit/') =>
            'PhabricatorPackagesPackageEditController',
        ),
        'version/' => array(
          $this->getQueryRoutePattern() =>
            'PhabricatorPackagesVersionListController',
          $this->getEditRoutePattern('edit/') =>
            'PhabricatorPackagesVersionEditController',
        ),
      ),
*/
        ),
    );
  }

  public function getStoreRoutes() {
      return array(
        '' => 'ExtensionStoreBrowseHomeController',
        'e/(?P<publisherKey>[^/]+)/' => array(
          '' => 'ExtensionStorePublisherBrowseController',
          '(?P<extensionKey>[^/]+)/' =>
            'ExtensionStoreExtensionBrowseController',
        ),
      );
  }

}
