import { Injectable } from '@angular/core';
import {
  CacheDataPath,
  CacheInterface,
  CacheLogic,
  Request,
  RequestCacheStateType,
} from './cache-logic/cache-logic-interface';
import { Cache } from './cache-logic/cache';
import { cacheCustomLogic } from './cache-logic/custom-cache-logic';

@Injectable({
  providedIn: 'root',
})
export class CacheService implements CacheInterface {
  private cache: Cache;

  constructor() {
    this.cache = new Cache(cacheCustomLogic);
    console.log('cache', this.cache);
  }

  getCacheLogic(): CacheLogic {
    return this.cache.getCacheLogic();
  }

  resetCache() {
    this.cache.resetCache();
  }

  getRequestCacheState(request: Request): RequestCacheStateType {
    return this.cache.getRequestCacheState(request);
  }

  mergeRequestResult(request: Request, response: any): void {
    return this.cache.mergeRequestResult(request, response);
  }

  getCacheData(cacheKey: CacheDataPath) {
    return this.cache.getCacheData(cacheKey);
  }
  getCacheDataByRequest(request: Request) {
    return this.cache.getCacheDataByRequest(request);
  }
  setCacheData(cacheKey: CacheDataPath, data: any) {
    return this.cache.setCacheData(cacheKey, data);
  }
  setCacheDataByRequest(request: Request, data: any) {
    return this.cache.setCacheDataByRequest(request, data);
  }

  deleteCacheData(cacheKey: CacheDataPath) {
    return this.cache.deleteCacheData(cacheKey);
  }
  deleteCacheDataByRequest(request: Request) {
    this.cache.deleteCacheDataByRequest(request);
  }
}
