import EuiReporter from '../core/reporter/eui-reporter.js'
import BambooEsPublisherTrigger from '@eui/automation/core/reporter/publishers/bamboo-es-publisher-trigger.js'
import S3Publisher from '@eui/automation/core/reporter/publishers/s3-publisher.js'
import tools from '@eui/tools/scripts/utils/tools.js'
const { vaultUser, vaultPassword } = tools.getArgs()
import * as master from '../wdio.conf.js'
import testSuites from './suites.json' assert { type: "json" }
const IMAGE_FOLDER_PREFIX = './packages/eui-automation/tests/wdioImages/'
import {join} from 'path'

export const config = Object.assign(master.config, {
  vaultConfig: {
    endpoint: 'https://vault.compasscorporate.eu/v1',
    user: vaultUser,
    password: vaultPassword
  },
  // vaultEnvVars takes all entries of the given vault secret and adds them as environment variables
  vaultEnvVars: {
    s3: {
      path: "/secret/functional/aws",
      key: "default"
    },
    sauce: {
      path: "/secret/functional/sauce",
      key: "default"
    }
  },
  screenshot: 'fail',  // never, fail or always
  browserlog: 'always',  // never, fail or always
  baseUrl: 'https://euidev.ecdevops.eu/',
  specs: ['./packages/eui-automation/tests/**/*.spec.js'],
  logLevel: 'error',
  suites: testSuites,
  maxInstances: 4,
  bail: 3,
  capabilities: [
    {
      browserName: "chrome",
      version: "latest",
      platform: 'Windows 10',
      name: "MWP - Saucelabs - CHROME",
      screenResolution: "1920x1080",
      "chromeOptions": {
        args: ['headless', 'window-size=1920,1080', 'disable-infobars', 'ignore-gpu-blacklist', 'test-type', 'disable-gpu'],
        // args: ['start-maximized', 'disable-infobars', 'ignore-gpu-blacklist', 'test-type', 'disable-gpu'],
      },
      // "goog:loggingPrefs": { browser: "ALL", driver: "ALL", performance: "ALL" },
      maxDuration: 5400,
      idleTimeout: 120
    },
  ],
  app: 'MWP',
  env: 'DEV',
  //SAUCE
  user: process.env.SAUCE_USERNAME,
  key: process.env.SAUCE_ACCESS_KEY,
  region: 'eu',
  useWdioImageComparison: true,
  services: ['sauce', ['image-comparison', {
    // Some options, see the docs for more
    baselineFolder: join(process.cwd(), IMAGE_FOLDER_PREFIX),
    formatImageName: '{tag}-{logName}-{width}x{height}',
    screenshotPath: join(process.cwd(), '.tmp/'),
    savePerInstance: true,
    autoSaveBaseline: true,
    blockOutStatusBar: true,
    blockOutToolBar: true,
    // NOTE: When you are testing a hybrid app please use this setting
    isHybridApp: true,
  }]],
  reporters: ['spec',
    ['allure', {
      outputDir: 'allure-results-dev-sauce',
      reportDir: 'allure-report-dev-sauce',
      cleanBefore: true,
      disableWebdriverStepsReporting: true,
      disableWebdriverScreenshotsReporting: false,
      openReport: false // CAREFULL, should be false when run on CI execution or other execution agent
    }],
    [EuiReporter, {
      loggerOptions: {
        reportDir: 'jsonReport'
      },
      publishers: [
        {
          type: S3Publisher,
          config: {
            publish: 'always',  // never, fail or always
            s3Server: "s3-website.eu-west-3.amazonaws.com",
            s3Bucket: "sonarreports",
            dirPath: "allure-report-dev-sauce",
            s3rootKey: "-eui-dev-report",
            prefixRootKeyWithTime: true,
            indexFile: "index.html"
          }
        },
        {
          type: BambooEsPublisherTrigger,
          config: {
            publish: 'always',  // never, fail or always
            vaultConfig: {
              endpoint: 'https://vault.compasscorporate.eu/v1',
              path: "/secret/functional/bamboo",
              key: "default",
            },
            buildKey: "CSDR-APMON",
            esConfig: {
              publish: 'always',  // never, fail or always
              protocol: 'https',
              host: 'es.tech.ec.europa.eu',
              port: '9200',
              index: 'eui-dev-saucelabs',
              deleteOldReports: true,
              keepMonthsHistoryNbr: 24,
              performanceLimits: {
                maxBaselineDeviationPercentages: {
                  'global': 50,
                  'DESCR duration': 50
                },
                warningTreshholds: {
                  'global': 40,
                  'DESCR duration': 3
                }
              },
              vaultConfig: {
                endpoint: 'https://vault.compasscorporate.eu/v1',
                path: "/secret/functional/elasticsearch",
                key: "default",
              }
            }
          }
        }
      ]
    }]]
});


