"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.saveProfileSection = saveProfileSection;
exports.getProfileSection = getProfileSection;
exports.getFullProfile = getFullProfile;
exports.deleteProfile = deleteProfile;
exports.deleteSection = deleteSection;
exports.profileExists = profileExists;
exports.profileCompletionStatus = profileCompletionStatus;
const database_1 = require("../database/database");
function ensureTable() {
    const db = (0, database_1.getDb)();
    db.exec(`
    CREATE TABLE IF NOT EXISTS developer_profile (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      section TEXT NOT NULL UNIQUE,
      raw_text TEXT NOT NULL,
      structured_data TEXT,
      importance INTEGER DEFAULT 85,
      created_at TEXT DEFAULT (datetime('now')),
      updated_at TEXT DEFAULT (datetime('now'))
    )
  `);
}
function saveProfileSection(section, rawText, structuredData, importance = 85) {
    const db = (0, database_1.getDb)();
    ensureTable();
    db.prepare(`
    INSERT INTO developer_profile (section, raw_text, structured_data, importance, updated_at)
    VALUES (?, ?, ?, ?, datetime('now'))
    ON CONFLICT(section) DO UPDATE SET
      raw_text = excluded.raw_text,
      structured_data = excluded.structured_data,
      importance = excluded.importance,
      updated_at = datetime('now')
  `).run(section, rawText, JSON.stringify(structuredData), importance);
}
function getProfileSection(section) {
    const db = (0, database_1.getDb)();
    ensureTable();
    const row = db.prepare('SELECT * FROM developer_profile WHERE section = ?').get(section);
    if (!row)
        return null;
    return {
        section: row.section,
        rawText: row.raw_text,
        structuredData: JSON.parse(String(row.structured_data || '{}')),
        importance: row.importance,
        createdAt: row.created_at,
        updatedAt: row.updated_at,
    };
}
function getFullProfile() {
    const db = (0, database_1.getDb)();
    ensureTable();
    const rows = db.prepare('SELECT section, raw_text, structured_data FROM developer_profile ORDER BY id').all();
    const profile = {};
    for (const row of rows) {
        profile[row.section] = {
            rawText: row.raw_text,
            structuredData: JSON.parse(String(row.structured_data || '{}')),
        };
    }
    return profile;
}
function deleteProfile() {
    const db = (0, database_1.getDb)();
    ensureTable();
    db.prepare('DELETE FROM developer_profile').run();
}
function deleteSection(section) {
    const db = (0, database_1.getDb)();
    ensureTable();
    db.prepare('DELETE FROM developer_profile WHERE section = ?').run(section);
}
function profileExists() {
    const db = (0, database_1.getDb)();
    ensureTable();
    const row = db.prepare('SELECT COUNT(*) as c FROM developer_profile').get();
    return row.c > 0;
}
function profileCompletionStatus(allSections) {
    const db = (0, database_1.getDb)();
    ensureTable();
    const rows = db.prepare('SELECT section FROM developer_profile').all();
    const done = rows.map(r => r.section);
    const pending = allSections.filter(s => !done.includes(s));
    return {
        done,
        pending,
        total: allSections.length,
        completionPercent: Math.round((done.length / allSections.length) * 100),
    };
}
//# sourceMappingURL=teach-store.js.map