import type { Models } from "@nontara/server/models";

export class OnboardSessionService {
	private account: Models.AccountData | null = null;
	private libraries: Models.LibraryData[] = [];
	private languages: Models.MetadataLanguage | null = null;

	public getAccount() {
		return this.account ?? ({} as Models.AccountData);
	}

	public updateAccount(account: Models.AccountData) {
		this.account = account;
	}

	public updateLibraries(libraries: Models.LibraryData[]) {
		this.libraries = libraries;
	}

	public getLibraries(): Models.LibraryData[] {
		return this.libraries.map((library) => ({ ...library }));
	}

	public getLanguage() {
		return this.languages ?? ({} as Models.MetadataLanguage);
	}

	public updateLanguage(languages: Models.MetadataLanguage) {
		this.languages = languages;
	}

	public dump(): Models.OnboardConfigurationData {
		if (!this.account) {
			throw new Error("Account not yet configured");
		}
		if (!this.languages) {
			throw new Error("Languages not yet configured");
		}
		return {
			account: this.account,
			languages: this.languages,
			libraries: this.libraries,
		};
	}
}
