import { Document, Schema } from 'mongoose';
import { ModuleResults, OverviewResults } from '../Report/Results';
import { Metadata } from '../Report/Feature';
import { Status } from '../Report/Status';
import { Tag } from '../Report/Scenario';

export interface MMetadata extends Metadata, Document {}
export interface MTag extends Tag, Document {}
export interface MModuleResults extends ModuleResults, Document {
  _id: any;
}
export interface MOverviewResults extends OverviewResults, Document {}

export const statusSchema = {
  ambiguous: 'ambiguous',
  failed: 'failed',
  passed: 'passed',
  pending: 'pending',
  skipped: 'skipped',
  undefined: 'undefined',
};

export const metadataSchema = new Schema( {
  icon: { required: false, type: String },
  name: { required: true, type: String },
  value: { required: true, type: String }
},{
  _id: false,
  id: false,
} );

export const tagSchema = new Schema( {
  line: { required: false,type: Number },
  name: { required: false, type: String }
},{
  _id: false,
  id: false,
} );

export const moduleResultsSchema = new Schema( {
  ambiguous: { required: true, type: Number },
  ambiguousPercentage: { required: true, type: Number },
  failed: { required: true, type: Number },
  failedPercentage: { required: true, type: Number },
  notdefinedPercentage: { required: true, type: Number },
  passed: { required: true, type: Number },
  passedPercentage: { required: true, type: Number },
  pending: { required: true, type: Number },
  pendingPercentage: { required: true, type: Number },
  skipped: { required: true, type: Number },
  skippedPercentage: { required: true, type: Number },
  status: { enum: Object.values( Status ), required: true, type: String },
  statusIcon: { required: false, type: String },
  time: { required: false, type: String },
  timeInNanoSeconds: { required: false, type: Number },
  total: { required: true, type: Number },
  undefined: { required: true , type: Number }
},{
  _id: false,
  id: false,
} );

export const overviewResultsSchema = new Schema( {
  ambiguous: { required: false, type: Number },
  ambiguousPercentage: { required: false, type: Number },
  duration: { required: false,type: Number },
  durationHHMMSS: { required: false, type: String },
  failed: { required: false, type: Number },
  failedPercentage: { required: false, type: Number },
  notdefinedPercentage: { required: false, type: Number },
  passed: { required: false, type: Number },
  passedPercentage: { required: false, type: Number },
  pending: { required: false, type: Number },
  pendingPercentage: { required: false, type: Number },
  skipped: { required: false, type: Number },
  skippedPercentage: { required: false, type: Number },
  status: { enum: Object.values( Status ), required: true,type: String },
  statusIcons: { required: false, type: String },
  time: { required: false, type: String },
  timeInNanoSeconds: { required: false, type: Number },
  total: { required: false, type: Number },
  undefined: { required: false, type: Number }
},{
  _id: false,
  id: false,
} );
