import { defineStore } from 'pinia'

// 唯一id：robot
export const useRobotStore = defineStore('robot', {
  state: () => ({
    ip: '192.168.1.110:50052',
    agvDeviceId:'src1100',
    almDeviceId: 'aubo_arm',
    position: { x: 0, y: 0, theta: 0 },
    battery: {
      percentage: 0.99,
      voltage: -0,
      current: -0,
      temperature: -0,
      charging: false
    },
    current_map: ''
  }),
  getters: {
    // 获取机器人坐标
    getPos(state) {
      return `X:${state.position.x} Y:${state.position.y}`
    },
    isLowPower(state) {
      return state.battery < 20
    }
  },
  actions: {
    setIp(str) {
        this.ip = str
    },
    setAgvDeviceId(str) {
        this.agvDeviceId = str
    },
    setAlmDeviceId(str) {
        this.almDeviceId = str
    },
    // 更新机器人位置
    setPosition(data = {}) {
      this.position = data
    },
    // 修改状态
    setBattery(data = {}) {
      this.battery = data
    },
    setCurrentMap(str = '') {
      this.current_map = str
    },
    // 重置仓库
    resetRobot() {
      this.$reset()
    }
  },
  // 开启本地存储
  persist: true
})