import { Injectable } from '@angular/core';
import { User } from '../entities';

const PARAM_USER = 'user';

@Injectable()
export class AuthService {
	constructor() {}

	public setAuthenticated(user: User): void {
		this.setUser(user);
	}
	public setAnonymous(): void {
		localStorage.clear();
	}

	public isAuthenticated(): boolean {
		return this.getUser() != null;
	}

	public isAdmin(): boolean {
		return false;
	}

	private setUser(user: User): void {
		localStorage.setItem(PARAM_USER, JSON.stringify(user));
	}

	public getUser(): User {
		return JSON.parse(localStorage.getItem(PARAM_USER));
	}
}
