import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, ResolveFn } from '@angular/router';
import { take } from 'rxjs/operators';

import { Profile } from '@models';
import { ProfilesService } from '@services';

export const profileResolver: ResolveFn<Profile> = (
    route: ActivatedRouteSnapshot
) => {
    return inject(ProfilesService).get(route.params['username']).pipe(take(1));
};