import { RouteBuilderImpl } from './services/route-builder/route-builder.service.impl';
import { RouteBuilder } from './services/route-builder/route-builder.service';
import { PageService } from './services/page/page.service';
import * as ng from '@types/angular';
import { NgModule } from 'angular-ts-decorators';
import { INJECTED_FEATURES } from './constants/injected-values.constant';
import { quayPages } from './quay-pages.module';


/**
 * Module containing client-side routing configuration.
 */
@NgModule({
  imports: [
    quayPages,
    'ngRoute',
  ],
  declarations: [],
  providers: [],
})
export class QuayRoutes {

  public config($routeProvider: ng.route.IRouteProvider,
                $locationProvider: ng.ILocationProvider,
                pages: PageService): void {
    $locationProvider.html5Mode(true);

    // WARNING WARNING WARNING
    // If you add a route here, you must add a corresponding route in thr endpoints/web.py
    // index rule to make sure that deep links directly deep into the app continue to work.
    // WARNING WARNING WARNING

    var routeBuilder: RouteBuilder = new RouteBuilderImpl($routeProvider, pages.$get());

    if (INJECTED_FEATURES.SUPER_USERS) {
      // QE Management
      routeBuilder.route('/superuser/', 'superuser')
      // QE Setup
        .route('/setup/', 'setup');
    }

    routeBuilder
      // Repository View
      .route('/repository/:namespace/:name', 'repo-view')
      .route('/repository/:namespace/:name/tag/:tag', 'repo-view')

      // Image View
      .route('/repository/:namespace/:name/image/:image', 'image-view')

      // Repo Build View
      .route('/repository/:namespace/:name/build/:buildid', 'build-view')

      // Repo Trigger View
      .route('/repository/:namespace/:name/trigger/:triggerid', 'trigger-setup')

      // Create repository notification
      .route('/repository/:namespace/:name/create-notification', 'create-repository-notification')

      // Repo List
      .route('/repository/', 'repo-list')

      // Organizations
      .route('/organizations/', 'organizations')

      // New Organization
      .route('/organizations/new/', 'new-organization')

      // View Organization
      .route('/organization/:orgname', 'org-view')

      // View Organization Team
      .route('/organization/:orgname/teams/:teamname', 'team-view')

      // Organization View Application
      .route('/organization/:orgname/application/:clientid', 'manage-application')

      // View Organization Billing
      .route('/organization/:orgname/billing', 'billing')

      // View Organization Billing Invoices
      .route('/organization/:orgname/billing/invoices', 'invoices')

      // View User
      .route('/user/:username', 'user-view')

      // View User Billing
      .route('/user/:username/billing', 'billing')

      // View User Billing Invoices
      .route('/user/:username/billing/invoices', 'invoices')

      // Sign In
      .route('/signin/', 'signin')

      // New Repository
      .route('/new/', 'new-repo')

      // Plans
      .route('/plans/', 'plans')

      // Tutorial
      .route('/tutorial/', 'tutorial')

      // Contact
      .route('/contact/', 'contact')

      // About
      .route('/about/', 'about')

      // Security
      .route('/security/', 'security')

      // TOS
      .route('/tos', 'tos')

      // Privacy
      .route('/privacy', 'privacy')

      // Change username
      .route('/updateuser', 'update-user')

      // Landing Page
      .route('/', 'landing')

      // Tour
      .route('/tour/', 'tour')
      .route('/tour/features', 'tour')
      .route('/tour/organizations', 'tour')
      .route('/tour/enterprise', 'tour')

      // Confirm Invite
      .route('/confirminvite', 'confirm-invite')

      // Enterprise marketing page
      .route('/enterprise', 'enterprise')

      // Public Repo Experiments
      .route('/__exp/publicRepo', 'public-repo-exp')

      // 404/403
      .route('/:catchall', 'error-view')
      .route('/:catch/:all', 'error-view')
      .route('/:catch/:all/:things', 'error-view')
      .route('/:catch/:all/:things/:here', 'error-view');
  }
}