import { Entry } from 'contentful';

interface ResolveEntryConfig {
    field: string;
    resolveTo: string;
}
interface ResolveEntryConfigMap {
    [field: string]: string;
}
interface OverrideConfig {
    field: string;
    options: {
        /**
         * Overrides the fieldname
         */
        fieldName?: string;
        /**
         * Method that transforms the value of the field.
         */
        valueTransformer?: (fieldValue: unknown) => unknown;
    };
}
interface OverrideConfigMap {
    [fieldName: string]: OverrideConfig['options'];
}
type CustomFieldsFunction = (entry: Entry) => unknown;
type CustomFieldsInput = CustomFieldsFunction | unknown;
type CustomFieldsConfig = Record<string, CustomFieldsInput>;
type fileExtensionBase = 'md' | 'yaml' | 'yml';
type fileExtension = fileExtensionBase | string;
interface TypeConfig {
    /**
     * Contentful content type ID
     */
    id: string;
    /**
     * Directory where entries will be placed
     */
    directory: string;
    type?: string;
    /**
     * The field that will act as the main content of the .md file
     */
    mainContent?: string;
    fileExtension?: fileExtension;
    /**
     * Options specifying how to resolve asset references and entry references
     */
    resolveEntries?: ResolveEntryConfig[] | ResolveEntryConfigMap;
    /**
     * Options that allow you to override field names and modify field values before rendering the content file.
     */
    overrides?: OverrideConfig[] | OverrideConfigMap;
    /**
     * Object of Contentful search filters. See https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters.
     */
    filters?: {
        [key: string]: string | number | boolean;
    };
    ignoreLocales?: boolean;
    customFields?: CustomFieldsConfig;
}
interface SingleTypeConfig extends TypeConfig {
    fileName: string;
}
interface RepeatableTypeConfig extends TypeConfig {
    isHeadless?: boolean;
    isTaxonomy?: boolean;
    /**
     * Entry property that will dictate the filename. Default is "sys.id".
     */
    fileName?: string;
}
interface ConfigContentfulSettings {
    /**
     * Contentful Space ID
     */
    space: string;
    /**
     * Contentful Content Delivery Token
     */
    token: string;
    /**
     * Contentful Content Preview Token
     */
    previewToken?: string;
    /**
     * Contentful environment ID
     */
    environment: string;
    /**
     * Number of entries to fetch per request.
     * Defaults to 1000
     */
    pageSize?: number;
}
type LocaleConfig = {
    /**
     * The Locale Code (Ex: en-US). This is case sensitive.
     */
    code: string;
    mapTo: string;
};
type StaticContentConfig = {
    inputDir: string;
    outputDir: string;
};
interface ContentfulHugoConfig {
    locales: (string | LocaleConfig)[];
    contentful: ConfigContentfulSettings;
    singleTypes: SingleTypeConfig[];
    repeatableTypes: RepeatableTypeConfig[];
    staticContent: StaticContentConfig[];
}

/**
 * Load Contentful Hugo config file
 */
declare const loadConfig: (
/**
 * Directory of the config file. (Default ".")
 */
rootDir?: string, 
/**
 * Config filename with extension.
 */
fileName?: string) => Promise<ContentfulHugoConfig | false>;
declare const defineConfig: (config: Partial<Omit<ContentfulHugoConfig, "contentful">> & {
    contentful?: Partial<ConfigContentfulSettings>;
}) => Partial<Omit<ContentfulHugoConfig, "contentful">> & {
    contentful?: Partial<ConfigContentfulSettings>;
};

/**
 * Add necessary config and shortcode files to current directory for Contentful-Hugo
 */
declare const initializeDirectory: (override?: boolean) => Promise<void>;

declare const copyStaticContent: (config: ContentfulHugoConfig) => Promise<void>;

interface ContentSettings {
    /**
     * Contentful content type ID
     */
    typeId: string;
    /**
     * The directory where the entries will be placed
     */
    locale: LocaleConfig;
    directory: string;
    fileExtension?: string;
    fileName?: string;
    titleField?: string;
    dateField?: string;
    /**
     * The field that will act as the main content in the .md file
     */
    mainContent?: string;
    isSingle?: boolean;
    isHeadless?: boolean;
    isTaxonomy?: boolean;
    type?: string;
    resolveEntries?: {
        field: string;
        resolveTo: string;
    }[];
    overrides?: OverrideConfig[];
    filters?: {
        [key: string]: string | number | boolean;
    };
    customFields: CustomFieldsConfig;
}
declare const fetchDataFromContentful: (
/**
 * Contentful Hugo Config Object
 */
config: ContentfulHugoConfig, 
/**
 * Fetch from the Content Preview API
 */
previewMode?: boolean, 
/**
 * Wait X number of ms before fetching data
 */
waitTime?: number) => Promise<void>;

export { copyStaticContent, defineConfig, fetchDataFromContentful, initializeDirectory, loadConfig };
export type { ContentSettings, ContentfulHugoConfig };
