import { toInteger } from 'lodash';
import api from './api'
import Common from './common';
import config from './config'
import Fetch from './fetch'
import moment from 'moment';
const common = new Common()
class CamMethods {


  async get_states_of_Alarm_Output_Channels() {
    const fetch = new Fetch()
    const parms = {
      'action': 'getOutState'
    }
    try {
      const data = await fetch.callGetApi(config.host + api.alarm, parms)
      console.log(data)
      var channel = data.replace('result=', '')
      channel = await common.convertToBinary(toInteger(channel))
      console.log('channel: ' + channel)
      if (channel !== '0') {
        console.log('something happened')
        const channels = await common.checkWhichChannelsIsTrue('11')
        const result = {
          id: moment().format('DDMMYYYYhhmmss').toString(),
          date: moment().format('DD/MM/YYYY hh:mm:ss').toString(),
          channels: channels,
          detection: await common.detectionHandler(channels),
        }
        console.log(result)
        //return the result
        return result
      } else {
        console.log('safe')
      }

    } catch (err) {
      console.log(err)
    }
  }




}

export default CamMethods