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

@Injectable({
  providedIn: 'root'
})
export class StorageService {
  saveToken(token: string, rememberMe: boolean): void {
    if (rememberMe) {
      localStorage.setItem('accessToken', token);
      localStorage.setItem('rememberMe', 'true');
    } else {
      sessionStorage.setItem('accessToken', token);
      localStorage.removeItem('rememberMe')
    }
  }

  getToken(): string | null {
    return localStorage.getItem('accessToken') || sessionStorage.getItem('accessToken');
  }

  clearToken(): void {
    localStorage.removeItem('accessToken');
    sessionStorage.removeItem('accessToken');
    localStorage.removeItem('rememberMe');
  }

  saveUserData(fullName: string | null, avatar: string | null): void {
    localStorage.setItem('userFullName', fullName || '');
    localStorage.setItem('avatar', avatar || '');
  }

  getUserFullName(): string | null {
    return localStorage.getItem('userFullName');
  }

  getAvatar(): string | null {
    return localStorage.getItem('avatar');
  }

  clearUserData(): void {
    localStorage.removeItem('userFullName');
    localStorage.removeItem('avatar');
  }
}
