import {
  AirtableTableLinks,
  BaseSyncConfig,
  ShopifyObjectType
} from '../../models';
import { MultipleRecordLinksField } from '../airtable';
import * as AirtableFields from '../airtable/AirtableFieldDefaultConfigs';

const { multipleRecordLinks } = AirtableFields;

export function getRecordLinkAirtableField({
  shopifyObjectType,
  airtableTableLinks,
  baseSyncConfig
}: {
    shopifyObjectType: ShopifyObjectType;
    airtableTableLinks: AirtableTableLinks;
    baseSyncConfig: BaseSyncConfig;
  }): MultipleRecordLinksField | null {
  const tableLink = airtableTableLinks[shopifyObjectType];
  const isObjectSynced = baseSyncConfig.shopify_object_types.includes(shopifyObjectType);

  return isObjectSynced ? {
    ...multipleRecordLinks,
    options: {
      ...multipleRecordLinks.options,
      linkedTableId: tableLink?.id
    }
  } : null;
}