import { Injectable } from "@nestjs/common";
import { PrismaService } from "./prisma.service";
import { AppGetaway } from "src/app.getaway";


@Injectable()
export class StatsService {
    constructor(
        private prisma: PrismaService,
        private socketService: AppGetaway
    ) { }

    async incrementVisits() {
        const stats = await this.prisma.stats.update({
            where: { id: 1 },
            data: { totalVisits: { increment: 1 } },
        });
        this.socketService.server.emit('statsUpdated', stats);
        return stats;
    }

    async incrementClicks() {
        const stats = await this.prisma.stats.update({
            where: { id: 1 },
            data: { totalClicks: { increment: 1 } },
        });
        this.socketService.server.emit('statsUpdated', stats);
        return stats;
    }

    async getStats() {
        return this.prisma.stats.findUnique({ where: { id: 1 } });
    }
}
