import { Injectable } from '@angular/core';
import {
  ActivatedRouteSnapshot,
  Resolve,
  Router,
  RouterStateSnapshot,
} from '@angular/router';
import { Observable } from 'rxjs';

import { IdentityService } from 'app/modules/polyglot/member/services/identity.service';
import { CaptchaResponse } from 'app/modules/protobuf/c2se/common/identity_pb';

@Injectable({
  providedIn: 'root',
})
export class CaptchaResolver implements Resolve<CaptchaResponse.Result> {
  /**
   * Constructor
   */
  constructor(
    private _identityService: IdentityService,
    private _router: Router
  ) {}

  // -----------------------------------------------------------------------------------------------------
  // @ Public methods
  // -----------------------------------------------------------------------------------------------------

  /**
   * Resolver
   *
   * @param route
   * @param state
   */
  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ):
    | Observable<CaptchaResponse.Result>
    | Promise<CaptchaResponse.Result>
    | CaptchaResponse.Result {
    return this._identityService.captcha();
  }
}
