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

import { ShopifyObjectModel } from './ShopifyObject';

export const OmittedLocationKeys = ['address', 'fulfillmentService', '__typename'] as const;
export type OmittedLocationKey = typeof OmittedLocationKeys[number];

export const LocationTypeName = 'locations';
export type LocationTypeName = typeof LocationTypeName;

type RemainingLocationKeys = Exclude<keyof LocationModelFragment, OmittedLocationKey>;

const RemainingLocationKeysRecord:Record<RemainingLocationKeys, undefined> = {
  activatable: undefined,
  addressVerified: undefined,
  deactivatable: undefined,
  deactivatedAt: undefined,
  deletable: undefined,
  fulfillsOnlineOrders: undefined,
  hasActiveInventory: undefined,
  hasUnfulfilledOrders: undefined,
  id: undefined,
  isActive: undefined,
  legacyResourceId: undefined,
  name: undefined,
  shipsInventory: undefined,
};

const RemainingLocationKeys = Object.keys(RemainingLocationKeysRecord) as readonly RemainingLocationKeys[];

const NewLocationKeys = [
  'address1',
  'address2',
  'city',
  'country',
  'countryCode',
  'latitude',
  'longitude',
  'phone',
  'province',
  'provinceCode',
  'zip',
  'fulfillmentService.id',
  'fulfillmentService.handle',
  'fulfillmentService.type',
] as const;

type LocationProps = Omit<LocationModelFragment, OmittedLocationKey> & {
  'address1': LocationModelFragment['address']['address1'];
  'address2': LocationModelFragment['address']['address2'];
  'city': LocationModelFragment['address']['city'];
  'country': LocationModelFragment['address']['country'];
  'countryCode': LocationModelFragment['address']['countryCode'];
  'latitude': LocationModelFragment['address']['latitude'];
  'longitude': LocationModelFragment['address']['longitude'];
  'phone': LocationModelFragment['address']['phone'];
  'province': LocationModelFragment['address']['province'];
  'provinceCode': LocationModelFragment['address']['provinceCode'];
  'zip': LocationModelFragment['address']['zip'];
  'fulfillmentService.id': NonNullable<LocationModelFragment['fulfillmentService']>['id'] | undefined;
  'fulfillmentService.handle': NonNullable<LocationModelFragment['fulfillmentService']>['handle'] | undefined;
  'fulfillmentService.type': NonNullable<LocationModelFragment['fulfillmentService']>['type'] | undefined;
};

export const LocationKeys = [
  ...RemainingLocationKeys,
  ...NewLocationKeys
] as const;

export interface Location extends ShopifyObjectModel {
    type: LocationTypeName;
    props: LocationProps;
}

export type LocationKey = keyof LocationProps;