import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';

import {AuthGuard, AuthUpdateGuard, AuthenticatedGuard, AnonymousGuard} from './auth/auth.guard';
import {ImprintComponent, PrivacyPolicyComponent, TermsOfServiceComponent} from './pages/general/general.component';
import {LoginComponent} from './pages/login/login.component';
import {LoginTotpComponent} from './pages/login-totp/login-totp.component';
import {FormLoginComponent} from './pages/form-login/form-login.component';
import {FormLoginTotpComponent} from './pages/form-login-totp/form-login-totp.component';
import {PasswordComponent} from './pages/password/password.component';
import {PasswordResetComponent} from './pages/password-reset/password-reset.component';
import {AccountComponent} from './pages/account/account.component';
import {RegisterComponent} from './pages/register/register.component';
import {TokensComponent} from './pages/tokens/tokens.component';
import {ServicesComponent} from './pages/services/services.component';
import {InfoComponent} from './pages/account/info/info.component';
import {ProfileComponent} from './pages/account/profile/profile.component';
import {VoucherComponent} from './pages/account/voucher/voucher.component';
import {SecurityComponent} from './pages/account/security/security.component';
import {UnavailableComponent} from './pages/unavailable/unavailable.component';
import {NotfoundComponent} from './pages/notfound/notfound.component';

const routes: Routes = [
  {path: '', redirectTo: "/account/info", pathMatch: 'full'},
  {path: 'imprint', component: ImprintComponent, canActivate: [AuthUpdateGuard]},
  {path: 'privacy-policy', component: PrivacyPolicyComponent, canActivate: [AuthUpdateGuard]},
  {path: 'terms-of-service', component: TermsOfServiceComponent, canActivate: [AuthUpdateGuard]},
  {path: 'login', component: LoginComponent, canActivate: [AnonymousGuard]},
  {path: 'login/totp', component: LoginTotpComponent, canActivate: [AnonymousGuard]},
  {path: 'service-login', component: FormLoginComponent, canActivate: [AnonymousGuard]},
  {path: 'service-login/totp', component: FormLoginTotpComponent, canActivate: [AnonymousGuard]},
  {path: 'password', component: PasswordComponent, canActivate: [AnonymousGuard]},
  {path: 'password-reset', component: PasswordResetComponent, canActivate: [AnonymousGuard]},
  {path: 'services', component: ServicesComponent, canActivate: [AuthenticatedGuard]},
  {
    path: 'account', component: AccountComponent, canActivate: [AuthenticatedGuard], children: [

      {path: 'info', component: InfoComponent, canActivate: [AuthenticatedGuard]},
      {path: 'profile', component: ProfileComponent, canActivate: [AuthenticatedGuard]},
      {path: 'voucher', component: VoucherComponent, canActivate: [AuthenticatedGuard]},
      {path: 'security', component: SecurityComponent, canActivate: [AuthenticatedGuard]}
    ]
  },
  {path: 'register', component: RegisterComponent, canActivate: [AnonymousGuard]},
  {path: 'tokens', component: TokensComponent, canActivate: [AuthGuard]},
  {path: 'unavailable', component: UnavailableComponent},
  {path: '**', component: NotfoundComponent, pathMatch: 'full'},
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})],
  exports: [RouterModule]
})
export class AppRoutingModule {}
