"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PortfolioModel = void 0;
const db_1 = require("../utils/db");
exports.PortfolioModel = {
    getAll() {
        return (0, db_1.getDb)()
            .prepare("SELECT * FROM portfolios ORDER BY created_at DESC")
            .all();
    },
    getByCategory(category) {
        return (0, db_1.getDb)()
            .prepare("SELECT * FROM portfolios WHERE category = ? ORDER BY created_at DESC")
            .all(category);
    },
    getById(id) {
        return (0, db_1.getDb)()
            .prepare("SELECT * FROM portfolios WHERE id = ?")
            .get(id);
    },
    create(data) {
        (0, db_1.getDb)()
            .prepare(`
        INSERT INTO portfolios (title, category, description, tech, demo_url, media_file_id, media_type)
        VALUES (@title, @category, @description, @tech, @demoUrl, @mediaFileId, @mediaType)
      `)
            .run({
            title: data.title,
            category: data.category,
            description: data.description,
            tech: data.tech,
            demoUrl: data.demoUrl ?? null,
            mediaFileId: data.mediaFileId ?? null,
            mediaType: data.mediaType ?? "photo",
        });
    },
    delete(id) {
        const result = (0, db_1.getDb)()
            .prepare("DELETE FROM portfolios WHERE id = ?")
            .run(id);
        return result.changes > 0;
    },
    count() {
        const row = (0, db_1.getDb)()
            .prepare("SELECT COUNT(*) as n FROM portfolios")
            .get();
        return row.n;
    },
};
