package net.cobem.grizzly.habbohotel;

import net.cobem.grizzly.Grizzly;
import net.cobem.grizzly.communication.composers.misc.SendNotificationComposer;
import net.cobem.grizzly.habbohotel.catalog.CatalogHandler;
import net.cobem.grizzly.habbohotel.furni.FurnitureHandler;
import net.cobem.grizzly.habbohotel.guild.GuildHandler;
import net.cobem.grizzly.habbohotel.misc.ChatCommandParser;
import net.cobem.grizzly.habbohotel.rooms.RoomHandler;
import net.cobem.grizzly.habbohotel.rooms.items.interactions.InteractionHandler;
import net.cobem.grizzly.habbohotel.rooms.models.ModelHandler;
import net.cobem.grizzly.habbohotel.sessions.SessionHandler;
import net.cobem.grizzly.habbohotel.stream.StreamHandler;

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

public class HabboHotel {
    private SessionHandler SessionHandler;
    private CatalogHandler CatalogHandler;
    private FurnitureHandler FurnitureHandler;
    private RoomHandler RoomHandler;
    private ModelHandler ModelHandler;
    private ChatCommandParser ChatCommandParser;
    private InteractionHandler InteractionHandler;
    private StreamHandler StreamHandler;
    private GuildHandler GuildHandler;

    public void load() throws SQLException {
        Grizzly.write("");

        SessionHandler = new SessionHandler();
        CatalogHandler = new CatalogHandler();
        FurnitureHandler = new FurnitureHandler();
        ModelHandler = new ModelHandler();
        RoomHandler = new RoomHandler();
        InteractionHandler = new InteractionHandler();
        ChatCommandParser = new ChatCommandParser();
        StreamHandler = new StreamHandler();
        GuildHandler = new GuildHandler();

        Grizzly.write("");
    }

    public SessionHandler getSessions() {
        return SessionHandler;
    }

    public CatalogHandler getCatalog() {
        return CatalogHandler;
    }

    public FurnitureHandler getFurniture() {
        return FurnitureHandler;
    }

    public RoomHandler getRooms() {
        return RoomHandler;
    }

    public ModelHandler getModels() {
        return ModelHandler;
    }

    public ChatCommandParser getCommands() {
        return ChatCommandParser;
    }

    public InteractionHandler getInteractions() {
        return InteractionHandler;
    }

    public StreamHandler getStream() {
        return StreamHandler;
    }

    public GuildHandler getGuilds() {
        return GuildHandler;
    }

    /*
     * Misc.
     */
    public int parseSmile(String Str) {
        if (Str.contains(":)") || Str.contains("=)") || Str.contains(":D") || Str.contains("=D")) {
            return 1;
        }

        if (Str.contains(":@") || Str.contains(">:(") || Str.contains(">:@")) {
            return 2;
        }

        if (Str.contains(":o") || Str.contains("D:")) {
            return 3;
        }

        if (Str.contains(":(") || Str.contains(":'(") || Str.contains("=(") || Str.contains("='(")) {
            return 4;
        }

        return 0;
    }

    public String generateName() {
        String Pool = "abcdefghijklmnopqrstuvwxyz";
        String Name = "";

        for (int i = 0; i < 5; i++) {
            if (Name.length() >= 3) {
                Name = Name + (new Random()).nextInt(26);
                continue;
            }

            Name = Name + Pool.split("")[(new Random()).nextInt(26)];
        }

        return Name;
    }

    public String generateLook() {
        Map<Integer, String> RandomLooks = new HashMap<Integer, String>();

        RandomLooks.put(1, "hr-555-1344.hd-3098-5.lg-3200-108.ch-655-1322.sh-905-1339");
        RandomLooks.put(2, "hr-3025-1348.hd-190-15.lg-285-1321.ch-3001-1324.sh-906-80");
        RandomLooks.put(3, "hr-835-54.hd-628-10.lg-3023-69.ch-818-93.sh-3016-1320");
        RandomLooks.put(4, "hr-115-41.hd-207-28.lg-3078-89.ch-808-1336.sh-300-72");
        RandomLooks.put(5, "hr-505-44.hd-615-10.lg-700-83.ch-3113-74.sh-905-81");
        RandomLooks.put(6, "hr-679-45.hd-180-1.lg-3116-66.ch-266.sh-908-64");
        RandomLooks.put(7, "hr-165-40.hd-3092-9.lg-280-67.ch-3001-68.sh-295-69");
        RandomLooks.put(8, "hr-890-46.hd-605-16.lg-3116-70.ch-675-73.sh-730-73");
        RandomLooks.put(9, "hr-890-52.hd-629-20.lg-700-96.ch-665-95.sh-3068-1334");
        RandomLooks.put(10, "hr-830-1342.hd-185-16.lg-285-101.ch-3030-90.sh-908-63");

        int Response = new Random().nextInt(RandomLooks.size());

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

        if (Response > RandomLooks.size()) {
            Response--;
        }

        return RandomLooks.get(Response);
    }

    public void sendHotelAlert(String Str) {
        getSessions().sendHotelMessage(SendNotificationComposer.compose(Str));
    }

    public void refreshCatalog(){
        getCatalog().refresh();
    }
}
