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

const PARAM_TOKEN = 'token';
const PARAM_USER = 'user';

@Injectable()
export class AuthService {
  authenticated: boolean = false;

	constructor() {}

  public setAuthenticated(pAuthenticated: boolean): void {
    this.authenticated = pAuthenticated;
  }

	public getToken(): string {
		return localStorage.getItem(PARAM_TOKEN);
	}

	public setToken(token: string): void {
		localStorage.setItem(PARAM_TOKEN, token);
	}

	public isAuthenticated(): boolean {
		return this.authenticated;
	}

	public disconnect(): void {
		localStorage.clear();
	}

	public isAdmin(): boolean {
		return false;
	}

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

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