import { Injectable } from '@angular/core';

@Injectable()
export class PreferencesProvider {

    tokenPrefix: string = "odix_token";
    hostPrefix: string = "odix_host";
    companyPrefix: string = "odix_company";
    partnerPrefix: string = "odix_partner";
    startPagePrefix: string = "odix_start_page";
    syncPrefix: string = "odix_sync";
    syncFrecuencyPrefix: string = "odix_sync_frecuency";

    constructor() { }

    /**
     *
     */
    setToken(token: string): void {
        localStorage.setItem(this.tokenPrefix, token);
    }

    /**
     *
     */
    getToken(): string {
        return localStorage.getItem(this.tokenPrefix);
    }

    /**
     *
     */
    setHost(host: string): void {
        localStorage.setItem(this.hostPrefix, host);
    }

    /**
     *
     */
    getHost(): string {
        return localStorage.getItem(this.hostPrefix);
    }

    /**
     *
     */
    setCompany(company: number): void {
        localStorage.setItem(this.companyPrefix, company.toString());
    }

    /**
     *
     */
    getCompany(): number {
        return +localStorage.getItem(this.companyPrefix);
    }

    /**
     *
     */
    setPartner(partner: number): void {
        localStorage.setItem(this.partnerPrefix, partner.toString());
    }

    /**
     *
     */
    getPartner(): number {
        return +localStorage.getItem(this.partnerPrefix);
    }

    /**
     *
     */
    setStartPage(page: number): void {
        localStorage.setItem(this.startPagePrefix, page.toString());
    }

    /**
     *
     */
    getStartPage(): number {
        return +localStorage.getItem(this.startPagePrefix);
    }

    /**
     *
     */
    setSync(sync: boolean): void {
        localStorage.setItem(this.syncPrefix, sync ? "true" : "false");
    }

    /**
     *
     */
    getSync(): boolean {
        return localStorage.getItem(this.syncPrefix) === "true";
    }

    /**
     *
     */
    setSyncFrecuency(frecuency: string) {
        localStorage.setItem(this.syncFrecuencyPrefix, frecuency);
    }

    /**
     *
     */
    getSyncFrecuency(): string {
        return localStorage.getItem(this.syncFrecuencyPrefix) ? "minute" : localStorage.getItem(this.syncFrecuencyPrefix);
    }

    /**
     *
     */
    clearPreferences(): void {
        localStorage.clear();
    }
}