<script>
import {authenticatedRequest} from "@/components/session/authenticatedRequest.vue";
import {handleEconomicError} from "@/components/request/HandleEconomicError.vue";
import { Layouts } from "@/components/session/token/superUser/modules/Economic/Layouts.vue";
import { PaymentTerms } from "@/components/session/token/superUser/modules/Economic/PaymentTerms.vue";
import { Config } from "@/components/session/token/superUser/modules/Economic/Config.vue";

/**
 * The Economic object
 */
export const Economic = {
  meta: {
    title: "E-conomic",
    icon: "fas fa-euro-sign",
    description: "Integration med Economic",
    endpoint: "/economic",
    config_endpoint: "/configuration/economic",
    labels: {
      single: "Economic",
      multiple: "Economic"
    }
  },
  layouts: Layouts,
  paymentTerms: PaymentTerms,
  config: Config,
  functions: {
    customers: {
      /**
       * Import customer from economic
       * @param customerNumber
       * @returns {Promise}
       */
      import: async (customerNumber) => {
        return authenticatedRequest(
            "/economic/customers/import",
            "POST",
            {
              customer_number: customerNumber
            }
        ).catch((error) => {
          handleEconomicError(error);
        });
      }
    },
    departments: {
      /**
       * Get department from economic
       * @returns {Promise}
       */
      get: async () => {
        return authenticatedRequest(
            "/economic/departments",
            "GET"
        ).catch((error) => {
          handleEconomicError(error);
        });
      }
    }
  }
};

</script>