using RobotLib.Communication;
using System.Collections.Generic;
using System.Text.Json;

namespace RobotLib.Movement
{
    public class DevMovement : DevBase
    {
        private const string TOPIC_MOBILE_MODE = "/mobile/cmd/mode/";
        private const string TOPIC_MOBILE_NAV_TURN = "/mobile/cmd/nav/turn/";
        private const string TOPIC_MOBILE_NAV_MOVE = "/mobile/cmd/nav/move/";
        private const string TOPIC_MOBILE_NAV_STOP = "/mobile/cmd/nav/stop/";

        public DevMovement(IPublisherSubscriber com) : base(com, new List<string>() { }) { }

        public void SetMobilityMode(bool automatic)
        {
            string payload = JsonSerializer.Serialize(new Dictionary<string, bool>() { { "automatic", automatic } });
            base.SendMessage(TOPIC_MOBILE_MODE, payload);
        }

        public void Turn(int angle)
        {
            base.SendMessage(TOPIC_MOBILE_NAV_TURN, angle.ToString());
        }

        public void AddSpeed(int speed)
        {
            base.SendMessage(TOPIC_MOBILE_NAV_MOVE, speed.ToString());
        }

        public void Stop()
        {
            base.SendMessage(TOPIC_MOBILE_NAV_STOP, true.ToString());
        }
    }
}
