/**
 * Carefirst Shared Global Interfaces
 *
 * @file          carefirst.shared.interfaces
 * @description   Interfaces for various globally shared data sets used in Carefirst
 * @author        Jacques Coetzee
 * @since         2021 - 11 - 16
 */

/**==============================================
 * @name         globalVariablesC
 * @description  Globally accessible variables used throughout various parts
 */
export const globalVariablesC = {
  companyShortNamesC: ['fcs', 'erc', 'shi', 'aiem', 'sgi'],
  dashboardHistoricTimeFramesC: [
    //--- Must be of type dashboardHistoricTimeframeTypeT[] as described in GlobalTypesT
    { label: 'Yesterday', property: 'yesterday', periodType: 'day', periodValue: 1, compareToPrevious: 'week', chartItemBreakdown: 'hour' },
    { label: 'Last 7 days', property: 'last7Days', periodType: 'day', periodValue: 7, compareToPrevious: 'month', chartItemBreakdown: 'day' },
    { label: 'Last 30 days', property: 'last30Days', periodType: 'day', periodValue: 30, compareToPrevious: 'year', chartItemBreakdown: 'day' },
    { label: 'Last 90 days', property: 'last90Days', periodType: 'day', periodValue: 90, compareToPrevious: 'year', chartItemBreakdown: 'day' },
    { label: 'Last 6 months', property: 'last6Months', periodType: 'month', periodValue: 6, compareToPrevious: 'year', chartItemBreakdown: 'month' },
    { label: 'Last 12 months', property: 'last1Year', periodType: 'month', periodValue: 12, compareToPrevious: 'year', chartItemBreakdown: 'month' },
  ],
  patientTriageC: ['Not Triaged', 'Green', 'Yellow', 'Orange', 'Red', 'Ward Visit'],
  telemedSourceToBreakdownC: ['nextpath', 'mtn', 'erc', 'shi'],
  chartItemBreakdownC: ['hour', 'day', 'month'],
  titleListC: ['MR', 'MRS', 'MS', 'MISS', 'MASTER', 'DR', 'PROF', 'REV', 'DS'],
  genderListC: ['M', 'F', 'O', 'N'], // M=Male F=Female O=Other N=Not Specified
  idNumberTypeC: [0, 1, 2], //0=National ID Number 1=Passport Number 2=Other
  fileUploadExtensionTypeListC: ['csv', 'pdf', 'png', 'jpg', 'xlsx'],
  //---<> Role check below is only temporary and may have to check profileType in the future
  scorecardAvailableRolesC: ['CCO', 'PCM', 'Doctor', 'CA'],
  // eslint-disable-next-line max-len
  //--- 0=Public Recipient; 1=Current (cheque/bond) account; 2=Savings account; 3=Transmission account; 4=Bond Account; 6=Subscription Share Account; D=eWallet Account (eWallet Pro); S=eWallet Account (Send Money); F=FNB Card Account; W=WesBank
  fnbAccountTypesC: ['0', '1', '2', '3', '4', '6', 'D', 'S', 'F', 'W'],
} as const;

/**==============================================
 * @name         GlobalTypesT
 * @description  Globally accessible types used throughout various parts
 */
export type GlobalTypesT = {
  companyShortNamesT: (typeof globalVariablesC.companyShortNamesC)[number];
  telemedSourceToBreakdownT: (typeof globalVariablesC.telemedSourceToBreakdownC)[number];
  patientTriageT: (typeof globalVariablesC.patientTriageC)[number];
  dashboardHistoricTimeframeTypeT: {
    label: string;
    property: (typeof globalVariablesC.dashboardHistoricTimeFramesC)[number]['property'];
    periodType: 'day' | 'month';
    periodValue: number;
    compareToPrevious: 'day' | 'week' | 'month' | 'year';
    chartItemBreakdown: (typeof globalVariablesC.chartItemBreakdownC)[number];
  };
  titleListT: (typeof globalVariablesC.titleListC)[number];
  genderListT: (typeof globalVariablesC.genderListC)[number];
  idNumberTypeListT: (typeof globalVariablesC.idNumberTypeC)[number];
  fileUploadExtensionTypeListT: (typeof globalVariablesC.fileUploadExtensionTypeListC)[number];
  scorecardAvailableRolesC: (typeof globalVariablesC.scorecardAvailableRolesC)[number];
  fnbAccountTypesT: (typeof globalVariablesC.fnbAccountTypesC)[number];
};

/**==============================================
 * @name          AccessIdentifiersT
 * @description   Available identifiers as defined in DB
 */
const availableUserRoleIdentifiersC = [
  'ercRevenue',
  'routeToolScorecards',
  'scorecardAdmin',
  'routeToolRefundRequest',
  'refundRequestVerification',
  'refundRequestAuthorization',
  'routeDashboardPaymentRequest',
  'routeDashboardRefundRequest',
  'routeDashboardERCCompanyOverview',
  'routeDashboardDoctorOverview',
  'routeDashboardERUnitOverview',
  'routeDashboardERUnitStaffing',
  'routeDashboardEMRUsage',
  'routeDashboardTelemedOverview',
  'routeDashboardExternalERUnitOverview',
  'routeDashboardExternalERUnitStaffing',
  'routeAdmin',
  'adminAccess',
  'adminAdmin',
  'adminUploads',
  'reportBookingPerHour',
  'reportDiagnosisMusculoskeletal',
  'reportUnitHM',
  'reportUnitUrit',
  'adminLearnworlds',
  'routeToolLMSErrors',
  'routeDashboardLMSOverview',
] as const;
export type AccessIdentifiersT = (typeof availableUserRoleIdentifiersC)[number];

/**==============================================
 * @name          GenericHistoricTimeFrames
 * @description   Generic type created from dashboardTimeFrames
 */
export type GenericHistoricTimeFrames<Type> = { [K in GlobalTypesT['dashboardHistoricTimeframeTypeT']['property']]: Type };

/**==============================================
 * @interface    SingleValueDataI
 * @description  SingeValue data type
 */
export interface SingleValueDataI {
  title: string;
  info: string;
  value: {
    curValue: number | null;
    fromPrevValue?: number | undefined; //--- Change from previous value (Negative value = downwards arrow)
    change?: 'positive' | 'negative' | undefined; //--- 'positive' = green | 'negative' = red
  };
  valueMod?: {
    //--- Various value modifications used by frontend template
    currency?: boolean; //--- add 'R ' as prefix and format as currency
    percentage?: boolean; //--- add '%' as suffix
    prefix?: string; //--- string to be added as prefix
    suffix?: string; //--- string to be added as suffix
    custom?: string; //--- Custom value to overwrite original value
  };
}

/**==============================================
 * @interface    SingleValueTimeFrameDataI
 * @description  SingeValue data type with timeframe breakdown
 */
export interface SingleValueTimeFrameDataI extends Omit<SingleValueDataI, 'value'> {
  value: GenericHistoricTimeFrames<SingleValueDataI['value']>;
}

/**==============================================
 * @interface    PatientRatingDataI
 * @description  Patient rating type
 */
export interface PatientRatingDataI extends Omit<SingleValueDataI, 'value'> {
  value: {
    doctor: number | undefined;
    facility: number | undefined;
    nurses: number | undefined;
  };
}

/**==============================================
 * @interface    PatientRatingTimeFrameDataI
 * @description  Patient rating per timeframe type
 */
export interface PatientRatingTimeFrameDataI extends Omit<PatientRatingDataI, 'value'> {
  value: GenericHistoricTimeFrames<PatientRatingDataI['value']>;
}

/**==============================================
 * @interface    ChartDataI
 * @description  Chart data type
 */
export interface ChartDataI {
  info: string;
  dimensions: string[]; //--- Array of legends
  source: [string, ...number[]][]; //--- Each element contains a data point of type ['label', number1, number2, ...]
}

/**==============================================
 * @interface    ChartTimeFrameDataI
 * @description  Chart data type with timeframe breakdown
 */
export interface ChartTimeFrameDataI extends Omit<ChartDataI, 'source'> {
  source: GenericHistoricTimeFrames<ChartDataI['source']>;
}

/**==============================================
 * @interface    GanttChartTemplateDataI
 * @description  Gantt chart data type as sent by backend directly to frontend template
 */
export interface GanttChartTemplateDataI {
  title?: string; //--- Chart title
  info?: string; //--- Info icon text
  color?: string; //--- Chart items color
  data: {
    id: number;
    axisLabel: string;
    itemsData: {
      start: string;
      end: string;
      hexColor?: string;
    }[];
  }[];
  dataZoom?: {
    start?: number; //--- Define initial start as percentage of data set
    end?: number; //--- Define initial end as percentage of data set
  };
}

/**==============================================
 * @interface    TableDiagnosesProceduresDataI
 * @description  Table entry data type for both diagnoses and procedures
 */
export type TableDiagnosesProceduresDataI = {
  code: string;
  description: string;
  count: number;
  percentageOfTotal: number;
}[];

/**==============================================
 * @interface    TableDiagnosesProceduresTimeFrameDataI
 * @description  Table data type for Diagnoses and Procedures with timeframe breakdown
 */
export type TableDiagnosesProceduresTimeFrameDataI = GenericHistoricTimeFrames<TableDiagnosesProceduresDataI>;

/**==============================================
 * @interface     DataTableTemplateDataI
 * @description   Table data type as sent by backend directly to frontend template
 */
export interface DataTableTemplateDataI {
  tableSetup: {
    limit: number; //--- Number of rows per page
    shadow?: true; //--- Add shadow to table border
    footer?: string; //--- Additional text in footer
    fillHeight?: true; //--- Fill parent height
  };
  colSetup: {
    fieldId: string; //--- Reference object field name in rowData;
    name: string; //--- Human readable column name
    flexRatio: number; //--- FlexGrow number to use for each column
    cellCenter: boolean; //--- Position of text in column
    currency?: boolean; //--- Display value as currency
    button?: boolean; //--- Display a button for user interaction
    buttonName?: string; //--- String to display in button
  }[];
  rowData: { [key: string]: unknown }[]; //--- Array of objects containing row data
}

/**==============================================
 * @interface    FileUploadFormDataFieldPayloadI
 * @description  Defines the field payload part of the FormData sent to the backend for uploading files
 */
export type FileUploadFormDataFieldPayloadI = FileUploadFormDataFieldUnitsPayloadI[] | FileUploadFormDataFieldUsersPayloadI[];
interface FileUploadFieldBaseI {
  fileName: string;
  fileType: number;
}
export interface FileUploadFormDataFieldUnitsPayloadI extends FileUploadFieldBaseI {
  unitId: number;
}
export interface FileUploadFormDataFieldUsersPayloadI extends FileUploadFieldBaseI {
  userId: number;
}
