import { keys } from 'lodash';
import { CustomerTypeName, InventoryLevelTypeName, LineItemTypeName, LocationTypeName, OrderTypeName, ProductTypeName, ProductVariantTypeName } from '../../models/shopify';
import { UnreachableCaseError } from '../../types';
import { isPresent } from '../../util';
import { getCustomerAirtableFields } from './getCustomerAirtableFields';
import { getInventoryLevelAirtableFields } from './getInventoryLevelAirtableFields';
import { getLineItemAirtableFields } from './getLineItemAirtableFields';
import { getLocationAirtableFields } from './getLocationAirtableFields';
import { getOrderAirtableFields } from './getOrderAirtableFields';
import { getProductAirtableFields } from './getProductAirtableFields';
import { getProductVariantsAirtableFields } from './getProductVariantAirtableFields';
function getShopifyObjectAirtableFields({ shopifyObjectType, airtableTableLinks, baseSyncConfig, }) {
    switch (shopifyObjectType) {
        case ProductTypeName: {
            return getProductAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        case ProductVariantTypeName: {
            return getProductVariantsAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        case OrderTypeName: {
            return getOrderAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        case LocationTypeName: {
            return getLocationAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        case InventoryLevelTypeName: {
            return getInventoryLevelAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        case LineItemTypeName: {
            return getLineItemAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        case CustomerTypeName: {
            return getCustomerAirtableFields({
                airtableTableLinks,
                baseSyncConfig
            });
        }
        default: {
            throw new UnreachableCaseError(shopifyObjectType);
        }
    }
}
export function getCreateFieldProps({ shopifyObjectType, airtableTableLinks, baseSyncConfig, shopifyObjectKey }) {
    const shopifyObjectAirtableFields = getShopifyObjectAirtableFields({
        shopifyObjectType,
        airtableTableLinks,
        baseSyncConfig,
    });
    return getModifyAirtableFieldProps({
        shopifyObjectType,
        airtableFields: shopifyObjectAirtableFields,
        fieldKey: shopifyObjectKey
    });
}
export function getCreateTableProps({ shopifyObjectType, airtableTableLinks, baseSyncConfig, }) {
    const shopifyObjectAirtableFields = getShopifyObjectAirtableFields({
        shopifyObjectType,
        airtableTableLinks,
        baseSyncConfig,
    });
    return getModifyAirtableFieldsProps({
        shopifyObjectType,
        airtableFields: shopifyObjectAirtableFields
    });
}
function getModifyAirtableFieldsProps({ shopifyObjectType, airtableFields, }) {
    return keys(airtableFields.fields)
        .map(fieldKey => getModifyAirtableFieldProps({
        shopifyObjectType,
        airtableFields,
        fieldKey: fieldKey,
    }))
        .filter(isPresent);
}
// Rather than using a generic that extends ShopifyObjectType it's better to directly pass shopifyObjectType
// if we can. While it adds another param to the function signature, we can take advantage of control-flow analysis,
// which Typescript does on regular variables, but *not on type variables*.
// Related StackOverflow answer:
// https://stackoverflow.com/a/60476282/4744177
export function getModifyAirtableFieldProps({ shopifyObjectType, airtableFields, fieldKey, }) {
    const { fields } = airtableFields;
    const field = fields[fieldKey];
    if (field === null) {
        return null;
    }
    return {
        ...field,
        name: fieldKey
    };
}
//# sourceMappingURL=getCreateTableProps.js.map