import { TestCase, TestResult } from "@playwright/test/reporter";

export interface AioConfig {
  enableReporting?: boolean;
  cloud: {
    apiKey: string;
  };
  hosted?: {
    jiraUrl: string;
    jiraPAT: string;
    jiraUsername: string;
    jiraPassword: string;
  };
  jiraProjectId: string;
  cycleDetails: {
    cycleKeyToReportTo?: string;
    createNewCycle?: boolean | string;
    cycleName?: string;
    cycleKey?: string;
    folder?: string[];
    tasks?: string[];
    customFields?: CustomField[];
  };
  runDetails?: {
    customFieldsToUpdate: CustomFieldUpdate[];
  };
  addNewRun: boolean;
  addAttachmentToFailedCases: boolean;
  createNewRunForRetries: boolean;
  newRunForRepeatedTest: boolean;
  addTestBodyToComments: boolean;
  debugMode: boolean;
  parallelBuild?: {
    masterBuild: boolean;
    waitForSeconds: number;
  };
}

export interface CustomField {
  name: string;
  value:
    | boolean
    | number
    | string
    | { value: string }
    | { value: string }[]
    | string[];
}

export interface CustomFieldUpdate {
  operationType?: string;
  name: string;
  value:
    | boolean
    | number
    | string
    | { value: string }
    | { value: string }[]
    | string[];
  //If multiple browsers are configured, using $project in the value field will replace it with the name of the browser used for the test.
}

export interface CustomFieldUpdateData {
  customValue: {
    name: string;
    value: any;
  };
  customFieldUpdateOperationType?: string;
}

export interface CreateCycleBody {
  title?: string;
  customFields: any | null;
  folder?: any;
  jiraTaskIDs?: string[];
}

export interface TestDataEntry {
  testId: string;
  duration: number;
  testStatus: string;
  screenshot?: (string | undefined)[];
  comments?: string[] | null;
  retires?: number;
  browser: string;
}

export interface BulkRequestBody {
  testRuns: {
    testCaseKey: string;
    testRunStatus: string;
    effort: number;
    isAutomated: boolean;
    comments?: string[] | null;
    customFieldValueToUpdate?: CustomFieldUpdateData[] | null;
  }[];
}

export interface TestData {
  test: TestCase;
  result: TestResult;
}
