import { prisma } from '../config/database';

// This service handles the model from the current
// spree app its serving from. We only need to know
// if the evaluation request with that token exists.
export class EvaluationLicenseRequestsService {
  public static async findBySecret(secret: string) {
    return prisma.evaluationLicenseRegistration.findFirst({
      where: { secret },
      select: { id: true, access_counter: true },
    });
  }

  public static async incrementAccessCounter(id: number) {
    return prisma.evaluationLicenseRegistration.update({
      where: { id },
      data: { access_counter: { increment: 1 } },
    });
  }
}
