import { InventoryLevelModelFragment } from '../../types/ShopifyGraphQLAdminAPI';

import { ShopifyObjectModel } from './ShopifyObject';

export const OmittedInventoryLevelKeys = ['__typename', 'item' ] as const;
export type OmittedInventoryLevelKey = typeof OmittedInventoryLevelKeys[number];

export const InventoryLevelTypeName = 'inventory_levels';
export type InventoryLevelTypeName = typeof InventoryLevelTypeName;

type RemainingInventoryLevelKeys = Exclude<keyof InventoryLevelModelFragment, OmittedInventoryLevelKey>;

const RemainingInventoryLevelKeysRecord:Record<RemainingInventoryLevelKeys, undefined> = {
  available: undefined,
  canDeactivate: undefined,
  createdAt: undefined,
  deactivationAlert: undefined,
  deactivationAlertHtml: undefined,
  id: undefined,
  location: undefined,
  incoming: undefined,
  updatedAt: undefined,
};

const RemainingInventoryLevelKeys = Object.keys(RemainingInventoryLevelKeysRecord) as readonly RemainingInventoryLevelKeys[];

const NewInventoryLevelKeys = [
  'inventoryItem.id',
  'location.id',
  'location.isActive',
  'location.name',
  'productVariant.id',
  'productVariant.sku',
  'productVariant.title',
  'product.title',
  'product.id',
  'product.handle',
  'productVariant',
] as const;

type InventoryLevelProps = Omit<InventoryLevelModelFragment, OmittedInventoryLevelKey> & {
  'inventoryItem.id': InventoryLevelModelFragment['item']['id'];
  'location.id': InventoryLevelModelFragment['location']['id'];
  'location.isActive': InventoryLevelModelFragment['location']['isActive'];
  'location.name': InventoryLevelModelFragment['location']['name'];
  'productVariant': InventoryLevelModelFragment['item']['variant'];
  'productVariant.id': InventoryLevelModelFragment['item']['variant']['id'];
  'productVariant.sku': InventoryLevelModelFragment['item']['variant']['sku'];
  'productVariant.title': InventoryLevelModelFragment['item']['variant']['title'];
  'product.title': InventoryLevelModelFragment['item']['variant']['product']['title'];
  'product.id': InventoryLevelModelFragment['item']['variant']['product']['id'];
  'product.handle': InventoryLevelModelFragment['item']['variant']['product']['handle'];
};

export const InventoryLevelKeys = [
  ...RemainingInventoryLevelKeys,
  ...NewInventoryLevelKeys
] as const;

export interface InventoryLevel extends ShopifyObjectModel {
    type: InventoryLevelTypeName;
    props: InventoryLevelProps;
}

export type InventoryLevelKey = keyof InventoryLevelProps;