import * as lodash from 'lodash';
import { Metadata } from './Feature';
import { Status } from './Status';
export interface ModuleResults {
  _id?: any;
  passed: number;
  failed: number;
  undefined: number;
  skipped: number;
  pending: number;
  ambiguous: number;
  total: number;
  passedPercentage: number;
  failedPercentage: number;
  notdefinedPercentage: number;
  skippedPercentage: number;
  pendingPercentage: number;
  ambiguousPercentage: number;
  status: Status;
  statusIcon?: string;
  time: string;
  timeInNanoSeconds: number;
}

export interface OverviewResults{
  duration: number;
  durationHHMMSS: string;
}

export interface ReportResultsOverview extends OverviewResults{
  _id?: any;
  status: Status;
  version?: string;
  date: Date;
  executionDate: string;
  executionTime: string;
  name?: string;
  duration: number;
  durationHHMMSS: string;
  metadata?: Metadata[];
}

export interface FeatureResultsOverview extends OverviewResults{
  statusIcons?: string[];
  status: string[];
}

export interface ScenarioResultsOverview extends OverviewResults{
  status: Status;
  isFirstScenarioOutline?: boolean;
}

export interface StepResultsOverview extends OverviewResults {
  status: Status;
  error_message?: string;
  icon: string;
  title: string;
  color: string;
}

export interface FeatureResults {
  overview: FeatureResultsOverview;
  scenarios: ModuleResults;
  steps: ModuleResults;
}

export interface ScenarioResults {
  overview: ScenarioResultsOverview;
  before: OverviewResults;
  after: OverviewResults;
  steps: ModuleResults;
}

export interface ReportResults {
  // _id?: any;
  overview: ReportResultsOverview;
  features: ModuleResults;
  scenarios: ModuleResults;
  steps: ModuleResults;
}

export interface BeforeOrAfterOverviewResults extends OverviewResults{
  status: Status;
}

export interface BeforeOrAfterResults{
  overview: BeforeOrAfterOverviewResults;
}

export const moduleResultsInitializer = (): ModuleResults => lodash.cloneDeep( {
  ambiguous: 0,
  ambiguousPercentage: 0,
  failed: 0,
  failedPercentage: 0,
  notdefinedPercentage: 0,
  passed: 0,
  passedPercentage: 0,
  pending: 0,
  pendingPercentage: 0,
  skipped: 0,
  skippedPercentage: 0,
  status: Status.passed,
  time: '',
  timeInNanoSeconds: 0,
  total: 0,
  undefined: 0,
} );

export const overviewInitializer = {
  duration: 0,
  durationHHMMSS: '',
  status: Status.passed
};

export const scenarioResultsInitializer = (): ScenarioResults => lodash.cloneDeep( {
  after: overviewInitializer,
  before: overviewInitializer,
  overview: overviewInitializer,
  steps: moduleResultsInitializer()
} );

export const featureResultsInitializer = (): FeatureResults => lodash.cloneDeep( {
  overview: {
    duration: 0,
    durationHHMMSS: '',
    status: [],
    statusIcons: []
  },
  scenarios: moduleResultsInitializer(),
  steps: moduleResultsInitializer()
} );

export const reportResultsInitializer = (): ReportResults => lodash.cloneDeep( {
  features: moduleResultsInitializer(),
  overview: {
    date: new Date(),
    duration: 0,
    durationHHMMSS: '',
    executionDate: '',
    executionTime: '',
    metadata: [] as Metadata[],
    name: '',
    status: Status.passed
  },
  scenarios: moduleResultsInitializer(),
  steps: moduleResultsInitializer()
} );
