import { TCalculationProcess } from 'client/stores/CalculationStore/subStores/calculationProcess';
import { TOptionizedEntity } from 'core/services/CrmService/types/common';
import { ICalculationStore } from 'core/types/Calculation/Store';
import { TElementFilter } from 'core/types/Calculation/Store/filters';
import { FC } from 'react';
import { ElementProps, ElementStatus } from 'types/elements';

export type TableNames = 'tableInsurance' | 'tablePayments' | 'tableResults';
export type TableValuesNames =
  | 'policyType'
  | 'insuranceCompany'
  | 'insured'
  | 'insCost'
  | 'insTerm'
  | 'paymentNumber'
  | 'paymentRelation'
  | 'paymentSum'
  | 'ndsCompensation'
  | 'redemptionAmount';

type CellCallback = (props: {
  calculationStore: ICalculationStore;
  calculationProcess: TCalculationProcess;
  tableName: TableNames;
  rowIndex: number;
  value: any;
}) => void;

export type Cell = {
  value?: any;
  status?: ElementStatus;
  validation?: boolean;
  filter?: TElementFilter;
};

export type Column = {
  name: TableValuesNames;
  title: string;
  Component: FC<any>;
  props?: ElementProps;
};

export type Table = {
  columns: Column[];
  rows: (Partial<Record<TableValuesNames, Cell>> & { key?: string })[];
  options?: Partial<Record<TableValuesNames, TOptionizedEntity[]>>;
  params?: { features?: Record<string, any> };
  callbacks?: Partial<Record<TableValuesNames, CellCallback>>;
};
