package net.cobem.grizzly.habbohotel.rooms.robots;

import net.cobem.grizzly.communication.EventResponse;
import net.cobem.grizzly.communication.HeaderLibrary;
import net.cobem.grizzly.habbohotel.pathfinding.Position;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class RobotAI {
    public Robot Robot;

    public Map<Integer, String> RandomPhrases;

    public int NewX;
    public int NewY;

    public boolean Terminate;
    public boolean IsMoving;

    public RobotAI(Robot mRobot) {
        RandomPhrases = new HashMap<>();

        this.Robot = mRobot;

        this.populatePhrases();
    }

    private void populatePhrases() {
        //TODO: Differentiate when a robot has a different type.
        RandomPhrases.put(1, "I am Frankenstein v1");
        RandomPhrases.put(2, "Why the hell is the gas so much?!?!");
        RandomPhrases.put(3, "King Henry my ass!");
        RandomPhrases.put(4, "Dude, Y.O.L.O!");
        RandomPhrases.put(5, "I went do to the dishes... but, then I got high..");
        RandomPhrases.put(6, "Maximillian Robespierre is my hero!!");
        RandomPhrases.put(7, "I had nothing else to say, so I said this.");
        RandomPhrases.put(8, "GRIZZLAY!!!");
        RandomPhrases.put(9, "If I was a butler, I would say: 'Would you like a drink?'");
        RandomPhrases.put(10, "A black, asian and hispanic walk into a bar..");
        RandomPhrases.put(11, "And then he says... here I am!");
        RandomPhrases.put(12, "Corpis Die!");
    }

    public void sayPhrase() {
        int Response = new Random().nextInt(RandomPhrases.size());

        if (Response == 0) {
            Response++;
        }

        //if (Response > RandomPhrases.size()) { Response--; }

        EventResponse Message = new EventResponse();

        Message.Initialize(HeaderLibrary.SendRoomChatEvent);
        Message.addInt(Robot.ID);
        Message.addString(RandomPhrases.get(Response));
        Message.addInt(0);
        Message.addInt(2);
        Message.addInt(0);
        Message.addInt(-1);

        Robot.CurrentRoom.sendMessage(Message);
    }

    public void say(String Statement) {
        EventResponse Message = new EventResponse();

        Message.Initialize(HeaderLibrary.SendRoomChatEvent);
        Message.addInt(Robot.ID);
        Message.addString(Statement);
        Message.addInt(0);
        Message.addInt(2);
        Message.addInt(0);
        Message.addInt(-1);

        Robot.CurrentRoom.sendMessage(Message);
    }

    public void leave() {
        IsMoving = false;
        Terminate = true;

        this.say("I gotta jet!");

        //Robot.CurrentRoom.removeRobot(Robot);
    }

    public void move() {
        IsMoving = true;

        Position NewPosition = Robot.CurrentRoom.getModel().getRandomSquare();

        NewX = NewPosition.X;
        NewY = NewPosition.Y;
    }
}
