"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LeadModel = void 0;
const db_1 = require("../utils/db");
exports.LeadModel = {
    create(data) {
        const db = (0, db_1.getDb)();
        db.prepare(`
      INSERT INTO leads
        (telegram_id, username, name, phone_number, service_type, project_name, features, deadline, budget)
      VALUES
        (@telegramId, @username, @name, @phoneNumber, @serviceType, @projectName, @features, @deadline, @budget)
    `).run(data);
    },
    countAll() {
        const db = (0, db_1.getDb)();
        const row = db.prepare("SELECT COUNT(*) as n FROM leads").get();
        return row.n;
    },
    countByStatus(status) {
        const db = (0, db_1.getDb)();
        const row = db
            .prepare("SELECT COUNT(*) as n FROM leads WHERE status = ?")
            .get(status);
        return row.n;
    },
    countHot() {
        const db = (0, db_1.getDb)();
        const row = db
            .prepare("SELECT COUNT(*) as n FROM leads WHERE is_hot = 1")
            .get();
        return row.n;
    },
    countToday() {
        const db = (0, db_1.getDb)();
        const row = db
            .prepare("SELECT COUNT(*) as n FROM leads WHERE date(created_at) = date('now')")
            .get();
        return row.n;
    },
    getNewLeads(limit = 10) {
        const db = (0, db_1.getDb)();
        return db
            .prepare("SELECT * FROM leads WHERE status IN ('new','hot') ORDER BY is_hot DESC, created_at DESC LIMIT ?")
            .all(limit);
    },
};
