import {
  httpPost
} from "../api/index"
import {
  api
} from "../api/all"
export default class ICINLocker {
  /**
   * *添加用户
   * @param {锁ID} _lockId
   * @param {门锁IMEI} _imei
   * @param {添加的用户ID} _userId
   * @param {用户的keyId} _keyId
   * @param {00普通用户 01管理员 FF超级管理员} _role
   * @param {操作类型 1: 添加 2： 删除} _action
   * @param {回调} callback
   */
  static addUserToLock(_lockId='', _imei='', _userId='', _role='', _action='', order='', _cardName='', _roomName='', callback) {
    var data = {
      lockerId: _lockId,
      imei: _imei,
      lockerUserId: _userId,
      keyId: _userId,
      role: _role,
      action: _action,
      order: order,
      cardName: _cardName,
      roomName: _roomName
    };
    httpPost(data, api.ZGduserOperation).then(res => {
      callback(res)
    })
  }

  /**
   * *添加指纹
   * @param {门锁ID} _lockId
   * @param {门锁IMEI} _imei
   * @param {用户ID – 最多20字节} _userId
   * @param {指纹类型 0:普通指纹，1：胁迫指} _fingerType
   * @param {文件字节数组} _file
   * @param {设置开始时间-8位timestamp字符串,eg:'00000000'} _startTime
   * @param {设置结束时间-8位timestamp字符串,eg:'FFFFFFFF'} _endTime
   * @param {是否为报警指纹，'00'为否，'01'为是} _alarmFinger
   * @param {超管的commonKey} _commonKey
   * @param {回调方法} callback
   */
  static addFingerPrints(_lockId, _imei, _userId, _fingerType, _file, _startTime, _endTime, _cardName,
    _roomName, callback) {
    var data3 = {
      code: "zg/addFingerPrint",
      data: {
        lockerId: _lockId,
        imei: _imei,
        lockerUserId: _userId,
        keyId: _userId,
        fingerType: _fingerType,
        order: 6216,
        file: _file,
        startTime: _startTime,
        endTime: _endTime,
        cardName: _cardName,
        roomName: _roomName
      }
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }

  /**
   * *删除指纹
   * @param {门锁ID} _lockId
   * @param {门锁IMEI} _imei
   * @param {用户ID – 最多20字节} _userId
   * @param {指纹类型 0:普通指纹，1：胁迫指} _fingerType
   * @param {2：删除 3：修改} _action
   * @param {指纹模板号} _fingerId
   * @param {设置开始时间-8位timestamp字符串,eg:'00000000'} _startTime
   * @param {设置结束时间-8位timestamp字符串,eg:'FFFFFFFF'} _endTime
   * @param {是否为报警指纹，'00'为否，'01'为是} _alarmFinger
   * @param {超管的commonKey} _commonKey
   * @param {回调方法} callback
   */
  static delFingerPrints(_lockId, _imei, _userId, _action, _fingerId, _fingerType, _startTime, _endTime, _cardName,
    _roomName, callback) {
    var data3 = {
      code: "zg/fpOperate",
      data: {
        lockerId: _lockId,
        imei: _imei,
        lockerUserId: _userId,
        keyId: _userId,
        fingerId: _fingerId,
        fingerType: _fingerType,
        order: 6218,
        action: _action,
        startTime: _startTime,
        endTime: _endTime,
        cardName: _cardName,
        roomName: _roomName
      }
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }
  /**
   * *修改指纹时间
   * @param {门锁ID} _lockId
   * @param {门锁IMEI} _imei
   * @param {用户ID – 最多20字节} _userId
   * @param {指纹类型 0:普通指纹，1：胁迫指} _fingerType
   * @param {2：删除 3：修改} _action
   * @param {指纹模板号} _fingerId
   * @param {设置开始时间-8位timestamp字符串,eg:'00000000'} _startTime
   * @param {设置结束时间-8位timestamp字符串,eg:'FFFFFFFF'} _endTime
   * @param {是否为报警指纹，'00'为否，'01'为是} _alarmFinger
   * @param {超管的commonKey} _commonKey
   * @param {回调方法} callback
   */
  static modifyFingerPrints(_lockId, _imei, _userId, _action, _fingerId, _fingerType, _startTime, _endTime,
    _cardName, _roomName,
    callback) {
    var data3 = {
      code: "zg/fpOperate",
      data: {
        lockerId: _lockId,
        imei: _imei,
        lockerUserId: _userId,
        keyId: _userId,
        fingerId: _fingerId,
        fingerType: _fingerType,
        order: 6217,
        action: _action,
        startTime: _startTime,
        endTime: _endTime,
        cardName: _cardName,
        roomName: _roomName
      }
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }
  /**
   * *添加身份证
   * @param {门锁ID} _lockId
   * @param {门锁IMEI} _imei
   * @param {用户ID – 最多20字节} _userId
   * @param {操作类型 1: 添加 2： 删除 3:修改} _action
   * @param {文件字节数组} _taskStatus 任务状态 1：提交任务
   * @param {文件字节数组} _cardNo 卡号 卡片唯一标识
   * @param {文件字节数组} _cardType 卡类型 （16 进制） ：typeA 在线卡 0x21 Mifare 在线卡 0x22 typeB 在线卡 0x23 身份证（在线）0x24 typeA 离线卡 0x71 Mifare 离线卡 0x72 typeB 离线卡 0x73
   * @param {设置开始时间-8位timestamp字符串,eg:'00000000'} _startTime
   * @param {设置结束时间-8位timestamp字符串,eg:'FFFFFFFF'} _endTime
   * @param {回调方法} callback
   */
  static RfCardRegister(_lockId, _imei, _userId, _action, _taskStatus, _cardNo, _cardType, _startTime, _endTime,
    order, _cardName, _roomName, callback) {
    var data3 = {
      code: "zg/cardOperate",
      data: {
        lockerId: _lockId,
        imei: _imei,
        lockerUserId: _userId,
        keyId: _userId,
        action: _action,
        taskStatus: _taskStatus,
        order: order,
        startTime: _startTime,
        endTime: _endTime,
        cardType: _cardType,
        cardNo: _cardNo,
        cardName: _cardName,
        roomName: _roomName
      },
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }
  static delCardRegister(_lockId, _imei, _userId, _action, _taskStatus, _cardNo, _cardType, _startTime, _endTime,
    order, cardIndex, _cardName, _roomName, callback) {
    var data3 = {
      code: "zg/cardOperate",
      data: {
        lockerId: _lockId,
        imei: _imei,
        lockerUserId: _userId,
        keyId: _userId,
        action: _action,
        taskStatus: _taskStatus,
        order: order,
        startTime: _startTime,
        endTime: _endTime,
        cardType: _cardType,
        cardNo: _cardNo,
        cardIndex: cardIndex,
        cardName: _cardName,
        roomName: _roomName
      },
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }

  /**
   * *添加密码
   * @param {门锁ID} _lockId
   * @param {门锁IMEI} _imei
   * @param {用户ID – 最多20字节} _userId
   * @param {r 操作类型 1: 添加 2: 删除 3：修} _action
   * @param {文件字节数组} password 密码长度为 6 位，建议不要采用同样数字组合和连续简单组合
   * @param {回调方法} callback
   */
  static addForeverPassword(_lockId, _imei, _userId, _action, _password, _passwordCount, _startTime, _endTime, order,
    _cardName, _roomName,
    callback) {
    var data3 = {
      code: "zg/tempPassword",
      data: {
        lockerId: _lockId,
        imei: _imei,
        order: order,
        lockerUserId: _userId,
        passwordCount: _passwordCount,
        keyId: _userId,
        passwordStartTime: _startTime,
        passwordEndTime: _endTime,
        action: _action,
        password: _password,
        cardName: _cardName,
        roomName: _roomName
      },
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }
  static delForeverPassword(_lockId, _imei, _userId, _action, _password, _passwordCount, _startTime, _endTime, order,
    passwordIndex, _cardName, _roomName, callback) {
    var data3 = {
      code: "zg/tempPassword",
      data: {
        lockerId: _lockId,
        imei: _imei,
        order: order,
        lockerUserId: _userId,
        passwordCount: _passwordCount,
        keyId: _userId,
        passwordStartTime: _startTime,
        passwordEndTime: _endTime,
        action: _action,
        password: _password,
        passwordIndex: passwordIndex,
        cardName: _cardName,
        roomName: _roomName
      },
    };
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })
  }



  /*
  LD下发函数
  */
  /**
   * *添加用户
   * @param {锁ID} _deviceNum
   * @param {门锁IMEI} _imei
   * @param {添加的用户ID} _userTelephone
   * @param {用户的keyId} _userPassword
   * @param {用户的蓝牙密码password} _pwd
   * @param {操作类型} _mode
   * @param {操作指令} _order
   * @param {锁用户有效期开始时间} _passwordStartTime
   * @param {锁用户有效期结束时间} _passwordEndTime
   * @param {回调} callback
   */
  static LDAddUser(_deviceNum='', _imei='', _userTelephone='', _userPassword='', _pwd='', _passwordStartTime='', _passwordEndTime='',
    _mode='', _order='', _cardName='', _roomName='', _pass='', callback) {
    var data = {
      imei: _imei,
      deviceNum: _deviceNum,
      userTelephone: _userTelephone,
      userPassword: _userPassword,
      password: _pwd,
      operateMode: _mode,
      order: _order,
      passwordStartTime: _passwordStartTime,
      passwordEndTime: _passwordEndTime,
      is: false,
      cardName: _cardName,
      roomName: _roomName,
      pass: _pass
    };
    httpPost(data, api.getDeviceOperateUserInfo).then(res => {
      callback(res)
    })
  }
  /**
   * *删除用户
   * @param {锁ID} _deviceNum
   * @param {门锁IMEI} _imei
   * @param {添加的用户ID} _userTelephone
   * @param {用户的keyId} _userPassword
   * @param {用户的蓝牙密码password} _pwd
   * @param {操作类型} _mode
   * @param {操作指令} _order
   * @param {锁用户有效期开始时间} _passwordStartTime
   * @param {锁用户有效期结束时间} _passwordEndTime
   * @param {回调} callback
   */
  static LDDeleteUser(_deviceNum, _imei, _userTelephone, _userPassword, _cardName, _roomName, callback) {
    var data = {
      imei: _imei,
      deviceNum: _deviceNum,
      userTelephone: _userTelephone,
      userPassword: _userPassword,
      password: "20210816",
      passwordStartTime: "20210813010101",
      passwordEndTime: "20680813010101",
      operateMode: 3,
      order: 6203,
      is: false,
      cardName: _cardName,
      roomName: _roomName
    };
    httpPost(data, api.getDeviceOperateUserInfo).then(res => {
      callback(res)
    })
  }
  static LDDeleteUserSurrenderLease(_deviceNum, _imei, _userTelephone, _userPassword,_order, _cardName, _roomName, callback) {
    var data = {
      imei: _imei,
      deviceNum: _deviceNum,
      userTelephone: _userTelephone,
      userPassword: _userPassword,
      password: "20210816",
      passwordStartTime: "20210813010101",
      passwordEndTime: "20680813010101",
      operateMode: 3,
      order: _order,
      is: false,
      cardName: _cardName,
      roomName: _roomName
    };
    httpPost(data, api.getDeviceOperateUserInfo).then(res => {
      callback(res)
    })
  }
  /**
   * *添加指纹
   * @param {锁ID} _deviceNum
   * @param {门锁IMEI} _imei
   * @param {添加的用户ID} _userTelephone
   * @param {用户的keyId} _userPassword
   * @param {用户的蓝牙密码password} _pwd
   * @param {操作类型} _mode
   * @param {操作指令} _order
   * @param {锁用户有效期开始时间} _passwordStartTime
   * @param {锁用户有效期结束时间} _passwordEndTime
   * @param {指纹数据长度length} _length
   * @param {指纹fpTimeId} _fpTimeId
   * @param {指纹数据fingerprint} _fingerprint
   * @param {回调} callback
   */
  static LDAddFingerPrints(_deviceNum, _imei, _userTelephone, _userPassword, _pwd, _passwordStartTime,
    _passwordEndTime,
    _mode, _order, _length, _fpTimeId, _fingerprint, _cardName, _roomName, _pass, callback) {
    var data = {
      imei: _imei,
      deviceNum: _deviceNum,
      userTelephone: _userTelephone,
      userPassword: _userPassword,
      password: _pwd,
      operateMode: _mode,
      order: _order,
      fingerprintStartTime: _passwordStartTime,
      fingerprintEndTime: _passwordEndTime,
      length: _length,
      fpTimeId: _fpTimeId,
      fingerprint: _fingerprint,
      is: false,
      cardName: _cardName,
      roomName: _roomName,
      pass: _pass
    };
    httpPost(data, api.fingerprintTransfer).then(res => {
      callback(res)
    })
  }
  /**
   * *添加身份证
   * @param {锁ID} _deviceNum
   * @param {门锁IMEI} _imei
   * @param {添加的用户ID} _userTelephone
   * @param {用户的keyId} _userPassword
   * @param {用户的蓝牙密码password} _pwd
   * @param {操作类型} _mode
   * @param {操作指令} _order
   * @param {锁用户有效期开始时间} _passwordStartTime
   * @param {锁用户有效期结束时间} _passwordEndTime
   * @param {指纹数据长度length} _length
   * @param {指纹fpTimeId} _fpTimeId
   * @param {指纹数据fingerprint} _fingerprint
   * @param {回调} callback
   */
  static LDRfCardRegister(_deviceNum='', _imei='', _userTelephone='', _userPassword='', _pwd='', _passwordStartTime='',
    _passwordEndTime='',_mode='', _order='', _cardName='', _roomName='', _pass='false', callback) {
    var data = {
      imei: _imei,
      deviceNum: _deviceNum,
      userTelephone: _userTelephone,
      userPassword: _userPassword,
      password: _pwd,
      operateMode: _mode,
      order: _order,
      passwordStartTime: _passwordStartTime,
      passwordEndTime: _passwordEndTime,
      is: false,
      cardName: _cardName,
      roomName: _roomName,
      pass: _pass
    };
    httpPost(data, api.getDeviceOperateUserInfo).then(res => {
      callback(res)
    })
  }



  static LDAddCertificate(row, callback) {
    var data = {}
    var content=JSON.parse(row.content)
    if (row.type == 1) {
      data = {
        imei: row.imei,
        deviceNum: row.deviceNum,
        userTelephone: content.userTelephone,
        userPassword: content.userPassword,
        password: content.password,
        operateMode: content.operateMode,
        order: content.order,
        fingerprintStartTime: content.fingerprintStartTime,
        fingerprintEndTime: content.fingerprintEndTime,
        length: content.length,
        fpTimeId: content.fpTimeId,
        fingerprint: content.fingerprint,
        is: false,
        cardName: content.cardName,
        roomName: content.roomName,
        pass: true
      };
      httpPost(data, api.fingerprintTransfer).then(res => {
        callback(res)
      })
      return
    } else {
      data = {
        imei: row.imei,
        deviceNum: row.deviceNum,
        userTelephone: content.userTelephone,
        userPassword: content.userPassword,
        password: content.password,
        operateMode: content.mode,
        order: content.order,
        passwordStartTime: content.passwordStartTime,
        passwordEndTime: content.passwordEndTime,
        is: false,
        cardName: content.cardName,
        roomName: content.roomName,
        pass: true
      };
    }
    httpPost(data, api.getDeviceOperateUserInfo).then(res => {
      callback(res)
    })
  }
  static ZGAddCertificate(row, callback) {
    var data3 = {}
    var content=JSON.parse(row.content)
    console.log(row)
    if (row.type == 1) {
      data3 = {
        code: "zg/addFingerPrint",
        data: {
          lockerId: row.deviceNum,
          imei: row.imei,
          lockerUserId: content.userPassword,
          keyId: content.userPassword,
          fingerType: 0,
          order: content.order,
          file: content.fingerprint,
          startTime: content.passwordStartTime,
          endTime: content.passwordEndTime,
          cardName: content.cardName,
          roomName: content.roomName
        }
      };
    }else if(row.type == 2){
      data3 = {
        code: "zg/cardOperate",
        data: {
          lockerId: row.deviceNum,
          imei: row.imei,
          lockerUserId: content.userPassword,
          keyId: content.userPassword,
          action: 1,
          taskStatus: 1,
          cardType: 36,
          cardNo: content.password,
          order: content.order,
          startTime: content.passwordStartTime,
          endTime: content.passwordEndTime,
          cardName: content.cardName,
          roomName: content.roomName
        },
      };
    }else if(row.type == 3){
      data3 = {
        code: "zg/cardOperate",
        data: {
          lockerId: row.deviceNum,
          imei: row.imei,
          lockerUserId: content.userPassword,
          keyId: content.userPassword,
          action: 1,
          taskStatus: 1,
          cardType: 50,
          cardNo: content.password,
          order: content.order,
          startTime: content.passwordStartTime,
          endTime: content.passwordEndTime,
          cardName: content.cardName,
          roomName: content.roomName
        },
      };
    }else if(row.type == 4){
      data3 = {
        code: "zg/tempPassword",
        data: {
          lockerId: row.deviceNum,
          imei: row.imei,
          lockerUserId: content.userPassword,
          keyId: content.userPassword,
          order: content.order,
          passwordCount: 255,
          passwordStartTime: content.passwordStartTime,
          passwordEndTime: content.passwordEndTime,
          action: 1,
          password: content.password,
          cardName: content.cardName,
          roomName: content.roomName
        },
      };
    }
    httpPost(data3, api.sendCommand).then(res => {
      callback(res)
    })

  }

}
