import { Identifier } from "typescript";
import { EXECUTION_TYPE_ENUM, PRIORITY_ENUM } from "./constants";

export interface IProject {
  id: number;
  name: string;
  prefix: string;
  dateCreated?: string;
  suitsNo?: number;
  casesNo?: number;
}

export interface IProjectInfo {
  id: number;
  name: string;
  dateCreated: number;
  createdBy: string | null;
  suitesNo: number;
  casesNo: number;
}

export interface ISuite {
  itemId: number;
  name: string;
  parentId?: number;
  ascendants: IAscendant[];
  type: string;
  junk: boolean;
  order: number;
  children: Array<ISuite | ISuiteCase>;
}
export interface ISectionInfo {
  id: number;
  ascendants: IAscendant[];
  parentId: number;
  projectId: number;
  name: string;
  values: string[];
}
export interface ISuiteCase {
  itemId: number;
  name: string;
  type: string;
  junk: boolean;
  order: number;
  externalId: number;
}

export interface ITestCase {
  id: number;
  parentId: number;
  name: string;
  summary: string;
  preconditions: string;
  versions: IVersion;
  version: { name: number; id: number };
  ascendants: IAscendant[];
  children: IStep[];
  values: any;
  coverage: { requirements: []; readOnly: boolean };
  priority: PRIORITY_ENUM;
  executionType: EXECUTION_TYPE_ENUM;
  externalId: number;
  obsolete: boolean;
  dateCreated: number;
  createdBy: string;
  lastUpdated: number;
  lastUpdatedBy: string;
  readOnly: boolean;
  testPlansReadOnly: boolean;
  containedInTestPlans: boolean;
  fromTestlink: boolean;
}

export interface IAscendant {
  name: string;
  level: number;
  itemId: number;
  itemType: string;
  itemName: string;
  prefix?: string;
}

export interface IVersion {
  id: number;
  name: number;
  obsolete: boolean;
  lastUpdated: number;
  lastUpdatedBy: string;
  last?: boolean;
}

export interface IStep {
  name: string;
  expectedResult: string;
  execution: number;
  order?: number;
}

export interface IKeywordCaseGroup {
  cases: IKeywordCase[];
  id: number;
  name: string;
}

export interface IKeywordCase {
  id: number;
  name: string;
  values: string;
  priority: PRIORITY_ENUM;
  executionType: EXECUTION_TYPE_ENUM;
}

export interface ITestPlan {
  id: number;
  name: string;
  notes: string | null;
  dateCreated: number;
  createdBy: string | null;
  obsolete: boolean;
  active: boolean;
  casesNo: number;
}

export interface ITestPlanCreationResponseDTO {
  item: {
    id: number;
    name: string;
  };
}

export interface IAddTestCaseToTestPlansResponseDTO {
  item: {
    testPlans: string;
  };
}

export interface IAddTestCasesToTestPlanResponseDTO {
  item: {
    id: number;
    name: string;
    notes: string | null;
  };
}

export interface IBuild {
  id: number;
  name: string;
  notes: string | null;
  dateCreated: string;
  createdBy: string | null;
}

export interface IBuildCreationResponseDTO {
  item: {
    id: number;
    name: string;
  };
}

export interface ITestExecution {
  testCaseId: number;
  testCaseVersionId: number;
  testerId: number;
  startDate: number;
  buildId: number;
  duration: number | null;
  message: string | null;
  status: string;
}

export interface IProjectKeyword {
  id: number;
  value: string;
}

export interface IProjectMetaData {
  project: number;
  keywords: any;
  test_plan: any;
  suite: any;
}

export interface ICustomField {
  id: number;
  name: string;
  typeId: number;
  projects: number[];
  values: ICustomFieldValue[];
}

export interface ICustomFieldValue {
  value: number;
  label: string;
  projects: number[];
}

export interface IUser {
  label: string;
  value: number;
}

export interface IGlobalData {
  projects: IProject[];
  suitsNo: number;
  casesNo: number;
  customFieldsInfo: ICustomField[];
  usersInfo: IUser[];
  templates: [];
}

export interface IUserData {
  tested_by: any;
  created_by: any;
  updated_by: any;
}

export interface ICustomFieldData {
  customField: any;
}

enum QueryNodeTypeEnum {
  and = "and",
  or = "or",
  not = "not",
  lt = "lt",
  gte = "gte",
  eq = "eq",
  in = "in",
  like = "like"
}

export interface IQueryNode {
  type: QueryNodeTypeEnum;
  property: string;
  left?: IQueryNode;
  right?: IQueryNode;
  operation?: IQueryNode;
  value: any;
}

export interface IUpdateCustomFieldResponseDTO {
  item: IItem;
}

export interface IItem {
  id: number;
  name: string;
  description: string;
  scopes: IScopes;
  values: IValuesEntity;
  executionSubtypes: any[];
}

export interface IScopes {
  testCase: boolean;
  testPlan: boolean;
  testExecution: boolean;
  requirement: boolean;
  executionParameter: boolean;
}

export interface IValuesEntity {
  id: number;
  name: string;
  description: string | null;
}

export interface IUpdateTestCaseRequestDTO {
  id: number;
  versionId: number;
  name: string;
  summary: string;
  preconditions: string;
  priority: PRIORITY_ENUM;
  executionType: EXECUTION_TYPE_ENUM;
  values: Array<{
    value: string;
  }>;
  steps: IStep[];
}

export interface IBulkUpdateTestCasePropertiesRequestDTO {
  casesIds: number[];
  properties: {
    preconditions?: {
      regex: string;
      newValue: string;
    };
    summary?: {
      regex: string;
      newValue: string;
    };
    step?: {
      regex: string;
      newValue: string;
    };
    expectedResult?: {
      regex: string;
      newValue: string;
    };
  };
  ignoreImmutable: boolean;
}

export interface ICreateTestCaseRequestDTO {
  projectId: number;
  parentId: number;
  name: string;
  priority: PRIORITY_ENUM;
  executionType: EXECUTION_TYPE_ENUM;
  summary: string;
  preconditions: string;
  values: Array<{
    value: string;
  }>;
  steps: IStep[];
}

export interface ICreateTestCaseResponseDTO {
  item: {
    id: number;
    order: number;
    name: string;
    summary?: any;
    preconditions?: any;
    externalId: number;
    values: any;
  };
}

export interface TemplateInfo {
  suite: string;
  name: string[];
  priority?: string;
  skip?: boolean;
  skipReason?: string;
  keywords?: string[];
  maintainers?: string[];
}
export type IGetSuggestTestCasesResponseDTO = Array<{
  itemId: number;
  prefix: string;
  name: string;
  externalId: number;
}>;

export interface SearchOptions {
  projectName: string;
  keywords?: string[];
  subtype?: string[];
  suiteName?: string;
  priority?: number[];
  caseName?: string;
  automatedBy?: string[];
  caseId?: string; // support case Id like JPT-1426
  dateUpdated?: string[] | string;
  dateCreated?: string[] | string;
}

export interface CaseInfo {
  id: string;
  suite: string;
  name: string;
  priority: string;
  ids: string[];
  keywords: string[];
  maintainers: string[];
  ascendants: string;
  docs: string[];
  testSteps?: stepsInfo[];
  preconditions?: string;
  accountType?: string;
  extensionType?: string;
  entryPoint?: string[];
  enterPoint?: string; //similar
}

export interface stepsInfo {
  step: string;
  expectedResult: string;
}
