import { Injectable } from "@nestjs/common";
import type { IdMapping, Prisma } from "@prisma/client";
import { BaseRepository } from "../base.repository.js";
import { PrismaService } from "../prisma.service.js";

@Injectable()
export class IdMappingRepository extends BaseRepository<
  IdMapping,
  Prisma.IdMappingUncheckedCreateInput,
  Prisma.IdMappingUncheckedUpdateInput,
  Prisma.IdMappingWhereUniqueInput,
  Prisma.IdMappingWhereInput
> {
  constructor(prisma: PrismaService) {
    super(prisma);
  }

  protected get delegate() {
    return this.prisma.idMapping;
  }

  async exists(where: Prisma.IdMappingWhereUniqueInput): Promise<boolean> {
    const result = await this.delegate.findUnique({
      where,
      select: { userId: true },
    });
    return result !== null;
  }
}
