import * as THREE from 'three'

/**
 * @param editor Editor
 * @param object THREE.Object3D
 * @constructor
 */
class ObjectAlarmCommand {
  constructor(editor, ModelId) {
    this.type = 'ObjectAlarmCommand'
    this.ModelId = ModelId
    this.editor = editor
    this.object = editor.getObjectById(ModelId)
  }

  exec(isAlarm = true) {
    if (!this.object) return
    if (isAlarm) {
      this.object.traverse(object => {
        if (object instanceof THREE.Mesh && !Object.hasOwnProperty.call(object.userData, 'isAxis')) {
          object.material.color = new THREE.Color('#ff0000')
          object.material.side = 2
          object.material.transparent = true
          object.material.opacity = 0.8
        }
      })
      // this.editor.playSoundCommand.exec('Alarm', true, this.ModelId)
    } else {
      this.object.traverse(object => {
        if (object instanceof THREE.Mesh) {
          const m = this.editor.objMaterial.get(object.id)
          if (m)object.material = m.clone()
        }
      })
      // this.editor.playSoundCommand.exec('Alarm', false, this.ModelId)
    }
  }
}

export { ObjectAlarmCommand }
