import { AdaptableForm } from '../PredefinedConfig/Common/AdaptableForm';
import { FormContext } from '../PredefinedConfig/Common/FormContext';
import { Report, ReportData, SystemReportNames } from '../PredefinedConfig/ExportState';
import { AdaptableColumn, AdaptableColumnDataType, BaseContext } from '../types';
/**
 * Options regarding Exporting data from AdapTable
 */
export interface ExportOptions {
    /**
     * Format of exported values; can be set for whole grid, for each data type, or on a per column basis (via a function)
     *
     * @defaultValue rawValue
     */
    exportFormatType?: DataFormatType | DataFormatDataType | ((dataFormatTypeContext: DataFormatTypeContext) => DataFormatType);
    /**
     * Optional custom format for Date columns when exporting
     *
     * @defaultValue undefined
     * @gridInfoItem
     */
    exportDateFormat?: string;
    /**
     * User-provided Report Destinations (in addition to those shipped in AdapTable)
     */
    customDestinations?: CustomDestination[];
    /**
     * Reports generated entirely by users (and not AdapTable)
     */
    externalReports?: ExternalReport[];
    /**
     * System Reports to use; leave blank for all, empty array for none
     *
     * @defaultValue  'Visual Data', 'All Data', 'Current Data', 'Selected Cells', 'Selected Rows',
     * @gridInfoItem
     */
    systemReportNames?: SystemReportNames;
    /**
     * Export destinations to use; leave blank for all, empty array for none
     *
     * @defaultValue 'Excel', 'CSV', 'Clipboard', 'JSON, 'Table'
     * @gridInfoItem
     */
    systemExportDestinations?: SystemExportDestinations;
    /**
     * Whether to add a timestamp as a suffix to exported file name
     *
     * @defaultValue false
     * @gridInfoItem
     */
    appendFileTimestamp?: boolean;
    /**
     * Provide a Bespoke File name for the Report
     * @param reportFileNameContext context about report being run
     */
    reportFilename?(reportFileNameContext: ReportFileNameContext): string;
    /**
     * Whether a Column is included in System Reports and available in UI for selection
     * @defaultValue true
     */
    isColumnExportable?: (exportableColumnContext: ExportableColumnContext) => boolean;
    /**
     * Function invoked before a Report is run, enabling users to preload the data before it is exported
     */
    preProcessExport?: (preProcessExportContext: PreProcessExportContext) => boolean | Promise<ReportData | boolean>;
}
/**
 * Context provided to `ExportOptions.processExport()` callback used when pre-processing Export
 */
export interface PreProcessExportContext extends BaseContext {
    /**
     * Report being exported
     */
    report: Report;
    /**
     * Returns Columns to export based on Report's `ReportColumnScope`
     * @param includePrimaryKey - whether to include the primary key column (defaults to `false`)
     */
    getReportColumns: (includePrimaryKey?: boolean) => AdaptableReportColumn[];
    /**
     * Returns row data which would typically be exported based on the Report's `ReportRowScope`
     * @param reportColumns - the columns to include in the report
     * @param includePrimaryKey - whether to include the primary key column (defaults to `false`)
     */
    getReportRowData: (reportColumns: AdaptableReportColumn[], includePrimaryKey?: boolean) => Record<string, any>[];
}
/**
 * Column which is included in a Report
 */
export interface AdaptableReportColumn {
    /**
     * ColumnID
     */
    columnId: string;
    /**
     * Column Header
     */
    friendlyName: string;
    /**
     * Field name to get the value from the row data (defaults to `columnId`)
     */
    field?: string;
    /**
     * DataType of the Column
     */
    dataType: AdaptableColumnDataType;
}
/**
 * Format of exported Data - 'rawValue' or 'formattedValue'
 */
export type DataFormatType = 'rawValue' | 'formattedValue';
/**
 * Defines a Report where all the data is provided entirely by the user
 */
export interface ExternalReport {
    /**
     * Name of the Report
     */
    name: string;
    /**
     * Function invoked to return the data (in the form of a `ReportData` object)
     */
    onRunReport: () => ReportData;
}
/**
 * Defines a custom Export destination
 */
export interface CustomDestination {
    /**
     * Name of Custom Destination (mandatory)
     */
    name: string;
    /**
     * Optional Adaptable Form; if provided, it must include Buttons that will execute the Export
     */
    form?: AdaptableForm<ExportFormContext>;
    /**
     * Optional Function invoked when Export is applied (used if no form is supplied)
     */
    onExport?: (reportContext: ReportContext) => void;
}
/**
 * Context required by functions when using an Export Button
 */
export interface ExportFormContext extends FormContext {
    /**
     * The exported report
     */
    report: Report;
    /**
     * The data in the report
     */
    reportData: ReportData;
    /**
     * Custom Export destination
     */
    customDestination: CustomDestination;
}
/**
 * List of System Export Destinations
 */
export type SystemExportDestinations = SystemExportDestination[];
/**
 * Export Destinations provided by AdapTable
 */
export type SystemExportDestination = 'Excel' | 'CSV' | 'Clipboard' | 'JSON' | 'Table';
/**
 * Report Context sent when using Custom Export Destinations
 */
export interface ReportContext extends BaseContext {
    /**
     * Definition of Report being Run
     */
    report: Report;
    /**
     * Data being exported in the Report
     */
    reportData: ReportData;
}
/**
 * Context used for setting whether a Column is exportable
 */
export interface ExportableColumnContext extends BaseContext {
    /**
     * Column to be exported
     */
    adaptableColumn: AdaptableReportColumn;
}
/**
 * Context used for providing a custom filename for a Report
 */
export interface ReportFileNameContext extends BaseContext {
    /**
     * Name of Report being run
     */
    reportName: string;
    /**
     * Report's destination
     */
    destination: SystemExportDestination | CustomDestination;
}
/**
 * Context provided when setting a Data Format Type for Export
 */
export interface DataFormatTypeContext extends BaseContext {
    /**
     * Column being exported
     */
    column: AdaptableColumn;
}
/**
 * Defines the Format Data Types for all Data Types
 */
export interface DataFormatDataType {
    /**
     * Data Format type for String columns
     */
    string?: DataFormatType;
    /**
     * Data Format type for Number columns
     */
    number?: DataFormatType;
    /**
     * Data Format type for Date columns
     */
    date?: DataFormatType;
}
