"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecommendationStore = void 0;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
class RecommendationStore {
    profilesPath;
    feedbackPath;
    profiles;
    feedback;
    constructor(cellDir) {
        this.profilesPath = path.join(cellDir, 'developer_profiles.json');
        this.feedbackPath = path.join(cellDir, 'recommendation_feedback.json');
        this.profiles = new Map();
        this.feedback = [];
        this.ensureDir(cellDir);
        this.load();
    }
    saveProfile(developerId, profile) {
        this.profiles.set(developerId, profile);
        this.saveProfiles();
    }
    getProfile(developerId) {
        return this.profiles.get(developerId);
    }
    getAllProfiles() {
        return new Map(this.profiles);
    }
    recordFeedback(event) {
        this.feedback.push(event);
        this.saveFeedback();
    }
    getFeedback() {
        return [...this.feedback];
    }
    getFeedbackForPattern(patternId) {
        return this.feedback.filter((f) => f.patternId === patternId);
    }
    getFeedbackForDeveloper(developerId) {
        return this.feedback.filter((f) => f.developerId === developerId);
    }
    clear() {
        this.profiles.clear();
        this.feedback = [];
        this.saveProfiles();
        this.saveFeedback();
    }
    saveProfiles() {
        const data = {
            profiles: Object.fromEntries(this.profiles),
        };
        fs.writeFileSync(this.profilesPath, JSON.stringify(data, null, 2), 'utf-8');
    }
    saveFeedback() {
        const data = { feedback: this.feedback };
        fs.writeFileSync(this.feedbackPath, JSON.stringify(data, null, 2), 'utf-8');
    }
    load() {
        if (fs.existsSync(this.profilesPath)) {
            try {
                const raw = fs.readFileSync(this.profilesPath, 'utf-8');
                const data = JSON.parse(raw);
                if (data.profiles) {
                    for (const [key, val] of Object.entries(data.profiles)) {
                        this.profiles.set(key, val);
                    }
                }
            }
            catch {
                this.profiles.clear();
            }
        }
        if (fs.existsSync(this.feedbackPath)) {
            try {
                const raw = fs.readFileSync(this.feedbackPath, 'utf-8');
                const data = JSON.parse(raw);
                if (data.feedback) {
                    this.feedback = data.feedback;
                }
            }
            catch {
                this.feedback = [];
            }
        }
    }
    ensureDir(dir) {
        if (!fs.existsSync(dir))
            fs.mkdirSync(dir, { recursive: true });
    }
}
exports.RecommendationStore = RecommendationStore;
//# sourceMappingURL=recommendation-store.js.map