import { mock } from 'bun:test';
import { createPrismaMock } from 'bun-mock-prisma';

import type { PrismaClient } from '@/generated/prisma/client';
import type { PrismaClientMock } from 'bun-mock-prisma';

export const prismaMock = createPrismaMock<PrismaClient>() as PrismaClientMock<PrismaClient>;
export const sendMailMock = mock(
  async (_input: {
    to: string;
    subject: string;
    html: string;
    text: string;
  }) => undefined
);
export const transactionMock = mock(
  async <T>(fn: (tx: PrismaClientMock<PrismaClient>) => Promise<T>) => fn(prismaMock)
);
export const dbMock = {
  complexUser: prismaMock.complexUser,
  complex: prismaMock.complex,
  user: prismaMock.user,
  complexInvitation: prismaMock.complexInvitation,
  sport: prismaMock.sport,
  $transaction: transactionMock,
};

mock.module('@/lib/prisma', () => ({
  __esModule: true,
  db: dbMock,
}));

mock.module('@/lib/mailer', () => ({
  __esModule: true,
  sendMail: sendMailMock,
}));

export const uuidV7Mock = mock(() => '00000000-0000-4000-8000-000000000001');

mock.module('uuid', () => ({
  __esModule: true,
  v7: uuidV7Mock,
}));
