/**
 * Iris Backend Engine v1.0
 * Paradigm: Hybrid [Z-Notation ∩ Kotlin ∩ Rust ∩ C++]
 * Generated for Neutron OS Framework
 */

// String.prototype expansion for Kotlin-like syntax
if (!String.prototype.contains) {
    String.prototype.contains = function(str) { return this.indexOf(str) !== -1; };
}

/** @class Iris :: Hybrid Engine Runtime */
const Iris = {
    isThinking: false,
    memory: [],
    MAX_MEMORY: 100,
    name: "Iris",

    logSystem: function(msg) {
        console.log(`[SYSTEM::${this.name}] ${msg}`);
    },

    clearMemory: function() {
        this.memory = [];
        this.logSystem("Memory Buffer Cleared.");
    },

    generateResponse: async function(input) {
        this.isThinking = true;
        let cleanInput = input.trim().toLowerCase();
        await new Promise(resolve => setTimeout(resolve, 1000));

        if (this.memory.length >= this.MAX_MEMORY) {
            this.memory.shift();
        }
        this.memory.push(cleanInput);

        let response = "";

        switch(true) {
            case ["hello", "hi", "halo"].includes(cleanInput):
                response = "Halo! Saya Iris, asisten virtual Anda di Neutron OS. Ada yang bisa saya bantu?";
                break;
            case cleanInput === "status":
            case cleanInput === "clear":
                this.clearMemory();
                response = "CLEAR_SIGNAL";
                break;
            case ["siapa kamu?", "who are you?"].includes(cleanInput):
                response = "Saya adalah entitas kecerdasan hibrida yang dibangun di atas protokol Iris.";
                break;
            case cleanInput === "fetch --logs":
                response = "Memuat log kernel... [OK] - " + this.memory.join(" | ");
                break;
            default:
                if (cleanInput.length === 0) {
                    response = "iris: Analysis :: No Schema Match. Mohon gunakan format perintah teknis.";
                } else if (cleanInput.contains("neutron")) {
                    response = "Neutron OS adalah masa depan interface minimalis. Saya di sini untuk mengelolanya.";
                } else {
                    response = `Input '${input}' diterima. Analysis status: OK.`;
                }
        }

        this.isThinking = false;
        return response;
    }
};

module.exports = { Iris };

