import { defineStore } from 'pinia'

// 唯一id：robot
export const useRobotStore = defineStore('robot', {
  state: () => ({
    ip: '192.168.0.100:50052',
    position: { x: 0, y: 0, angle: 0 },
    battery: 100,
    status: 'idle'
  }),
  getters: {
    // 获取机器人坐标
    getPos(state) {
      return `X:${state.position.x} Y:${state.position.y}`
    },
    isLowPower(state) {
      return state.battery < 20
    }
  },
  actions: {
    setIp(str) {
        this.ip = str
    },
    // 更新机器人位置
    setPosition(x, y, angle) {
      this.position.x = x
      this.position.y = y
      this.position.angle = angle
    },
    // 修改状态
    setStatus(val) {
      this.status = val
    },
    // 重置仓库
    resetRobot() {
      this.$reset()
    }
  },
  // 开启本地存储
  persist: true
})