import { CustomerTypeName } from './Customer';
import { InventoryLevelTypeName } from './InventoryLevel';
import { LineItemTypeName } from './LineItem';
import { LocationTypeName } from './Location';
import { OrderTypeName } from './Order';
import { ProductTypeName } from './Product';
import { ProductVariantTypeName } from './ProductVariant';

import { ShopifyObjectType } from '.';

export enum SHOPIFY_OBJECT_FAMILY {
    PRODUCTS_AND_INVENTORY = 'products_inventory_family',
    ORDERS = 'orders_family',
    MISC = 'misc_family',
}

/**
 * Note: these are in hierarchical order with parents preceding children
 */
export const ShopifyObjectFamilyToTypes = {
  [SHOPIFY_OBJECT_FAMILY.PRODUCTS_AND_INVENTORY]: [ProductTypeName, ProductVariantTypeName, InventoryLevelTypeName],
  [SHOPIFY_OBJECT_FAMILY.ORDERS]: [OrderTypeName, CustomerTypeName, LineItemTypeName],
  [SHOPIFY_OBJECT_FAMILY.MISC]: [LocationTypeName],
} as const;

export type ShopifyObjectFamilyToTypes = typeof ShopifyObjectFamilyToTypes;

export const ShopifyObjectTypeToFamily:Record<ShopifyObjectType, SHOPIFY_OBJECT_FAMILY> = {
  [OrderTypeName]: SHOPIFY_OBJECT_FAMILY.ORDERS,
  [LineItemTypeName]: SHOPIFY_OBJECT_FAMILY.ORDERS,

  // For now... later we may want to have customers be their own category
  [CustomerTypeName]: SHOPIFY_OBJECT_FAMILY.ORDERS,
  [ProductTypeName]: SHOPIFY_OBJECT_FAMILY.PRODUCTS_AND_INVENTORY,
  [ProductVariantTypeName]: SHOPIFY_OBJECT_FAMILY.PRODUCTS_AND_INVENTORY,
  [InventoryLevelTypeName]: SHOPIFY_OBJECT_FAMILY.PRODUCTS_AND_INVENTORY,
  [LocationTypeName]: SHOPIFY_OBJECT_FAMILY.MISC,
} as const;

type a = ShopifyObjectFamilyToTypes[SHOPIFY_OBJECT_FAMILY.PRODUCTS_AND_INVENTORY][number];