import { Injectable } from '@angular/core';
import { LOCAL_STORAGE_KEYS } from 'src/assets/constants';
import { IPosConfigGoldPricePayload, IPosConfigGoldPriceResponse } from '../models';

@Injectable({ providedIn: 'root' })
export class PosConfigGoldPriceService {
  get(): IPosConfigGoldPriceResponse {
    const defaultPrice = Number(
      window.localStorage.getItem(LOCAL_STORAGE_KEYS.POS_CONFIG_GOLD_PRICE) || '0'
    );

    this.submit(defaultPrice);
    return defaultPrice;
  }

  submit(data: IPosConfigGoldPricePayload) {
    window.localStorage.setItem(LOCAL_STORAGE_KEYS.POS_CONFIG_GOLD_PRICE, data.toString());
  }
}
