import { PrismaClient, ShardStatus } from '@prisma/client';

// We no longer export a default prisma instance here to avoid initialization conflicts.
// Consumers should provide their own configured PrismaClient instance.
// export const prisma = new PrismaClient();

export * from '@prisma/client';

export interface IShardStatusRepository {
  upsertStatus(shardId: number, status: string, guilds: string[]): Promise<ShardStatus>;
  getStatus(shardId: number): Promise<ShardStatus | null>;
}

export class PrismaShardStatusRepository implements IShardStatusRepository {
  constructor(private db: PrismaClient) {}

  async upsertStatus(shardId: number, status: string, guilds: string[]): Promise<ShardStatus> {
    return this.db.shardStatus.upsert({
      where: { id: shardId },
      update: { status, guilds },
      create: { id: shardId, status, guilds },
    });
  }

  async getStatus(shardId: number): Promise<ShardStatus | null> {
    return this.db.shardStatus.findUnique({ where: { id: shardId } });
  }
}
