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

@Injectable({ providedIn: 'root' })
export class PosConfigPrintService {
  get(): IPosConfigPrintResponse {
    const data = window.localStorage.getItem(LOCAL_STORAGE_KEYS.POS_CONFIG_PRINT);
    if (data) {
      return JSON.parse(data) as IPosConfigPrintResponse;
    }
    const defaultData = {
      business_name: true,
      complex_name: true,
      pos_name: true,
      invoice_template: true,
      fiscal_id: true,
      economic_code: true,
      customer_name: true,
      customer_mobile: true,
      customer_national_id: true,
      customer_postal_code: true,
      customer_economic_code: true,
      payment_type: true,
      show_payment_info: true,
      show_items: false,
      items: {
        name: false,
        sku: false,
        quantity: false,
        base_amount: false,
        tax: false,
        discount: false,
        karat: false,
        profit: false,
        commission: false,
        wage: false,
        total_amount: false,
      },
    };
    this.submit(defaultData);
    return defaultData;
  }

  submit(data: IPosConfigPrintRequestPayload) {
    window.localStorage.setItem(LOCAL_STORAGE_KEYS.POS_CONFIG_PRINT, JSON.stringify(data));
  }
}
