/*
 * ******************************************************************
 * Copyright (c) 2025 Broadcom. All Rights Reserved.
 * Broadcom Confidential. The term "Broadcom" refers to Broadcom Inc.
 * and/or its subsidiaries.
 * ******************************************************************
 */
import { Injectable, Injector, Inject, Optional } from '@angular/core';
import { CONTAINER_CREDENTIALS, Credentials } from '../environments/access';
import { Router } from '@angular/router';

@Injectable({
	providedIn: 'root'
})
export class AppConfigService {
	constructor(
		private injector: Injector,
		@Inject(CONTAINER_CREDENTIALS) @Optional() private credentials: Credentials
	) {}

	login(): Promise<string[]> {
		if (!this.credentials) {
			console.group('(authentication)');
			console.log('No credentials provided. Authentication skipped.');
			console.groupEnd();
			return Promise.resolve(["", ""]);
		}

		console.group('(authentication)');
		console.log('Token credentials provided. Session creation skipped.');
		console.groupEnd();
		return Promise.resolve([this.credentials.jwt, this.credentials.authtoken]);
	}

	configureRoutes(): Promise<boolean> {
		return new Promise<boolean>(resolve => {
			console.group('(routing)');
			const router: Router = this.injector.get(Router);
			router.resetConfig(router.config);
			console.log('Updated router configuration');
			console.groupEnd();

			resolve(true);
		});
	}
}
