/* eslint-disable camelcase */
const axios = require('axios')
const config = require('./config')

const headers = {
  Accept: 'application/json',
  Authorization: config.authorization,
  Cookie: config.cookie,
  'content-type': 'application/json',
}

const dataEnedisAccount = JSON.stringify({
  account_type: 'enedissgegrandlyon',
  name: '',
  auth: {
    address: '6 Rue Vaillant Couturier',
    city: 'Vénissieux',
    firstname: 'Jane',
    lastname: 'Doe',
    pointId: '19170766804121',
    postalCode: '69200',
  },
  data: {
    consentId: 43,
    expirationDate: '2023-09-26',
    offPeakHours: '22H00-6H00',
  },
  id: '70e68b8450cee09fe2f077610901094d',
  identifier: 'address',
  state: null,
})

const dataGrdfAccount = JSON.stringify({
  account_type: 'grdfgrandlyon',
  auth: {
    credentials_encrypted:
      'bmFjbMKrNCS+4Liakxdu+xNu9I3sSyvda8iAp0o3U3OAymbIeoLhLtxPdsa+3mu/8yTnDudBcJo=',
    login: 'test',
  },
  id: '89e68b8450cee09fe2f077610901094d',
  identifier: 'login',
  state: null,
})

const dataEglAccount = JSON.stringify({
  account_type: 'eglgrandlyon',
  auth: {
    credentials_encrypted:
      'bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=',
    login: 'test',
  },
  id: '90e68b8450cee09fe2f077610901094d',
  identifier: 'login',
  state: null,
})

const dataEnedisTrigger = JSON.stringify({
  data: {
    attributes: {
      _id: '3ed832cec67e6e0b2c6382edd30df11c',
      domain: 'cozy.tools:8080',
      prefix: 'cozy35ba44d2d1749e6f21646edce51e7190',
      type: '@cron',
      worker: 'konnector',
      arguments: '0 47 8 * * *',
      debounce: '',
      options: null,
      message: {
        account: '70e68b8450cee09fe2f077610901094d',
        konnector: 'enedissgegrandlyon',
      },
      cozyMetadata: {
        doctypeVersion: '1',
        metadataVersion: 1,
        createdAt: '2020-10-09T08:00:00.6092798Z',
        createdByApp: 'ecolyo',
        updatedAt: '2020-10-09T08:00:00.6092798Z',
      },
    },
  },
})

const dataGrdfTrigger = JSON.stringify({
  data: {
    attributes: {
      _id: '4ed832cec67e6e0b2c6382edd30df11c',
      domain: 'cozy.tools:8080',
      prefix: 'cozy35ba44d2d1749e6f21646edce51e7190',
      type: '@cron',
      worker: 'konnector',
      arguments: '0 47 8 * * *',
      debounce: '',
      options: null,
      message: {
        account: '89e68b8450cee09fe2f077610901094d',
        konnector: 'grdfgrandlyon',
      },
      cozyMetadata: {
        doctypeVersion: '1',
        metadataVersion: 1,
        createdAt: '2020-10-09T08:00:00.6092798Z',
        createdByApp: 'ecolyo',
        updatedAt: '2020-10-09T08:00:00.6092798Z',
      },
    },
  },
})

const dataEglTrigger = JSON.stringify({
  data: {
    attributes: {
      _id: '5ed832cec67e6e0b2c6382edd30df11c',
      domain: 'cozy.tools:8080',
      prefix: 'cozy35ba44d2d1749e6f21646edce51e7190',
      type: '@cron',
      worker: 'konnector',
      arguments: '0 47 8 * * *',
      debounce: '',
      options: null,
      message: {
        account: '90e68b8450cee09fe2f077610901094d',
        konnector: 'eglgrandlyon',
      },
      cozyMetadata: {
        doctypeVersion: '1',
        metadataVersion: 1,
        createdAt: '2020-10-09T08:00:00.6092798Z',
        createdByApp: 'ecolyo',
        updatedAt: '2020-10-09T08:00:00.6092798Z',
      },
    },
  },
})

async function launch() {
  // Enedis
  await axios({
    method: 'put',
    url: 'http://cozy.tools:8080/data/io.cozy.accounts/70e68b8450cee09fe2f077610901094d',
    headers: headers,
    data: dataEnedisAccount,
  })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
    })
    .catch(function (error) {
      console.log(error)
    })

  await axios({
    method: 'post',
    url: 'http://cozy.tools:8080/jobs/triggers',
    headers: headers,
    data: dataEnedisTrigger,
  })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
    })
    .catch(function (error) {
      console.log(error)
    })

  // GRDF
  await axios({
    method: 'put',
    url: 'http://cozy.tools:8080/data/io.cozy.accounts/89e68b8450cee09fe2f077610901094d',
    headers: headers,
    data: dataGrdfAccount,
  })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
    })
    .catch(function (error) {
      console.log(error)
    })

  await axios({
    method: 'post',
    url: 'http://cozy.tools:8080/jobs/triggers',
    headers: headers,
    data: dataGrdfTrigger,
  })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
    })
    .catch(function (error) {
      console.log(error)
    })

  // EGL
  await axios({
    method: 'put',
    url: 'http://cozy.tools:8080/data/io.cozy.accounts/90e68b8450cee09fe2f077610901094d',
    headers: headers,
    data: dataEglAccount,
  })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
    })
    .catch(function (error) {
      console.log(error)
    })

  await axios({
    method: 'post',
    url: 'http://cozy.tools:8080/jobs/triggers',
    headers: headers,
    data: dataEglTrigger,
  })
    .then(function (response) {
      console.log(JSON.stringify(response.data))
    })
    .catch(function (error) {
      console.log(error)
    })
}

launch()