import { notStrictEqual } from 'node:assert';
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
import { PrismaClient } from '../../generated/prisma/client.js';
import { env } from '$env/dynamic/private';

export class PrismaClientFactory {
    private constructor(private readonly databaseUrl: string) {}
    public static fromEnv(): PrismaClientFactory {
        const value = env.PRIVATE_DATABASE_URL ?? '';
        notStrictEqual(value, '', `"env.PRIVATE_DATABASE_URL" must be defined`);

        return new PrismaClientFactory(value);
    }

    createClient(): PrismaClient {
        const adapter = new PrismaBetterSqlite3({ url: this.databaseUrl });
        const prisma = new PrismaClient({ adapter });
        return prisma;
    }
}
