"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserModel = void 0;
const db_1 = require("../utils/db");
exports.UserModel = {
    upsert(data) {
        const db = (0, db_1.getDb)();
        db.prepare(`
      INSERT INTO users (telegram_id, username, first_name, last_name, last_active)
      VALUES (@telegramId, @username, @firstName, @lastName, datetime('now'))
      ON CONFLICT(telegram_id) DO UPDATE SET
        username    = excluded.username,
        first_name  = excluded.first_name,
        last_name   = excluded.last_name,
        last_active = datetime('now')
    `).run(data);
    },
    countAll() {
        const db = (0, db_1.getDb)();
        const row = db.prepare("SELECT COUNT(*) as n FROM users").get();
        return row.n;
    },
    countSubscribed() {
        const db = (0, db_1.getDb)();
        const row = db
            .prepare("SELECT COUNT(*) as n FROM users WHERE is_subscribed = 1")
            .get();
        return row.n;
    },
    countToday() {
        const db = (0, db_1.getDb)();
        const row = db
            .prepare("SELECT COUNT(*) as n FROM users WHERE date(joined_at) = date('now')")
            .get();
        return row.n;
    },
    getAllSubscribed() {
        const db = (0, db_1.getDb)();
        return db
            .prepare("SELECT * FROM users WHERE is_subscribed = 1")
            .all();
    },
};
