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

import { ShopifyObjectModel } from './ShopifyObject';

export const OmittedProductKeys = ['seo', 'options', '__typename'] as const;
export type OmittedProductKey = typeof OmittedProductKeys[number];

type RemainingProductKey = Exclude<keyof ProductModelFragment, OmittedProductKey>;
const RemainingProductKeysRecord:Record<RemainingProductKey, undefined> = {
  createdAt: undefined,
  description: undefined,
  descriptionHtml: undefined,
  handle: undefined,
  id: undefined,
  isGiftCard: undefined,
  legacyResourceId: undefined,
  onlineStoreUrl: undefined,
  productType: undefined,
  publishedAt: undefined,
  requiresSellingPlan: undefined,
  status: undefined,
  storefrontId: undefined,
  tags: undefined,
  title: undefined,
  updatedAt: undefined,
  vendor: undefined,
  featuredImage: undefined,
};
const RemainingProductKeys = Object.keys(RemainingProductKeysRecord) as readonly RemainingProductKey[];

const NewProductKeys = [
  'seo.description',
  'seo.title',
  'options.1',
  'options.2',
  'options.3',
] as const;
type NewProductKeys = typeof NewProductKeys[number];

type ProductProps = Omit<ProductModelFragment, OmittedProductKey> & {
  'seo.description': ProductModelFragment['seo']['description'];
  'seo.title': ProductModelFragment['seo']['title'];
  'options.1': ProductModelFragment['options'][0]['name'];
  'options.2': ProductModelFragment['options'][1]['name'];
  'options.3': ProductModelFragment['options'][2]['name'];
};

export const ProductKeys = [
  ...RemainingProductKeys,
  ...NewProductKeys
] as const;

export type ProductKey = (typeof ProductKeys)[number];

export const ProductTypeName = 'products';
export type ProductTypeName = typeof ProductTypeName;

export interface Product extends ShopifyObjectModel {
  type: ProductTypeName;
  props: ProductProps;
}