import { Injectable } from "@angular/core";
import { ActivatedRoute, ActivatedRouteSnapshot, ParamMap, Resolve } from "@angular/router";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { Candidate } from "../models/candidate";
import { Observable } from "rxjs";
import { CandidateService } from "../services/candidate.service";
import { filter, map, switchMap, tap } from "rxjs/operators";

@Injectable()
export class CandidatDetailResolver implements Resolve<Candidate> {
  constructor(public service: CandidateService, private route: ActivatedRoute) {}
  resolve(): Observable<Candidate> {
      return this.route.queryParams.pipe(
        map(params => params['candidatId']),
        switchMap(candidatId => this.service.candidatGetById(candidatId)),
      );
    }
}
