import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { OnlineBoardRequestParserService } from '@online-board/services/request/request-parser.service';
import { IOnlineBoardRequestData } from '@online-board/types';

@Injectable()
export class OnlineBoardRequestDataResolver
    implements Resolve<IOnlineBoardRequestData>
{
    constructor(private requestService: OnlineBoardRequestParserService) {}

    resolve(
        route: ActivatedRouteSnapshot,
    ): IOnlineBoardRequestData | undefined {
        const { request } = route.queryParams;

        return (
            request && {
                raw: request,
                parsed: this.requestService.parse(request),
            }
        );
    }
}
