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

/**
 * The Stripe object
 */
export const Stripe = {
  meta: {
    title: "Stripe",
    icon: "fas fa-credit-card",
    description: "Stripe integration",
    endpoint: "/modules/stripe",
    config_endpoint: "/configuration/stripe",
    labels: {
      single: "Stripe",
      multiple: "Stripe"
    }
  },
  config: Config,
  functions: {
    customers: {
      list: async () => {
        return authenticatedRequest(
            "/modules/stripe/customers",
            "GET")
      },
    },
    products: {
      list: async () => {
        return authenticatedRequest(
            "/modules/stripe/products",
            "GET")
      },
    },
    prices: {
      list: async () => {
        return authenticatedRequest(
            "/modules/stripe/prices",
            "GET")
      },
    },
    terminals: {
      readers: {
        list: async () => {
          return authenticatedRequest(
              "/modules/stripe/terminal/readers",
              "GET")
        },
        listDepartment: async (departmentId) => {
          return authenticatedRequest(
              "/modules/stripe/department/terminal/readers?id=" + departmentId,
              "GET")
        },
      },
      locations: {
        list: async () => {
          return authenticatedRequest(
              "/modules/stripe/terminal/locations",
              "GET")
        },
        getDepartmentLocation: async (departmentId) => {
          return authenticatedRequest(
              "/modules/stripe/department/terminal/location?id=" + departmentId,
              "GET")
        },
        setDepartmentLocation: async (departmentId, locationId) => {
          return authenticatedRequest(
              "/modules/stripe/department/terminal/location",
              "POST",
              {
                id: departmentId,
                location: locationId
              })
        },
      },
    },
  },
  departments: {
    terminals: {
      location: {
        get: async (departmentId) => {return Stripe.functions.terminals.locations.getDepartmentLocation(departmentId)},
        set: async (departmentId, locationId) => {return Stripe.functions.terminals.locations.setDepartmentLocation(departmentId, locationId)},
      },
      readers: {
        list: async (departmentId) => {return Stripe.functions.terminals.readers.listDepartment(departmentId)},
      },
    },
  },
};

</script>