import { Inject, Injectable } from '@nestjs/common';
import { AgendaJob, Prisma } from '@prisma/client';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { PrismaService } from 'nestjs-prisma';
import { Logger } from 'winston';

import { ConfigService } from '@nestjs/config';

@Injectable()
export class AgendaJobService {
  constructor(
    private prisma: PrismaService,
    private readonly config: ConfigService,
    @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
  ) {}

  async createOne(agendaJobCreateArgs: Prisma.AgendaJobCreateArgs) {
    return await this.prisma.agendaJob.create(agendaJobCreateArgs);
  }

  async createMany(data: Prisma.AgendaJobCreateManyArgs['data']) {
    return await this.prisma.agendaJob.createMany({
      data,
      skipDuplicates: true,
    });
  }

  async findMany(
    agendaJobFindManyArgs: Prisma.AgendaJobFindManyArgs,
  ): Promise<{ itemCount: number; entities: AgendaJob[] }> {
    const itemCount = await this.prisma.agendaJob.count({
      where: agendaJobFindManyArgs.where,
    });
    const entities = await this.prisma.agendaJob.findMany(
      agendaJobFindManyArgs,
    );
    return { itemCount, entities };
  }

  async findUnique(
    id: string,
    select: Prisma.AgendaJobFindUniqueArgs['select'],
  ) {
    return await this.prisma.agendaJob.findUnique({
      where: { id: id },
      select,
    });
  }

  async updateMany(agendaJobUpdateManyArgs: Prisma.AgendaJobUpdateManyArgs) {
    return await this.prisma.agendaJob.updateMany(agendaJobUpdateManyArgs);
  }

  async updateUnique(id: string, data: Prisma.AgendaJobUpdateManyArgs['data']) {
    return await this.prisma.agendaJob.update({
      where: { id: id },
      data,
    });
  }

  async deleteMany(agendaJobDeleteManyArgs: Prisma.AgendaJobDeleteManyArgs) {
    return await this.prisma.agendaJob.deleteMany(agendaJobDeleteManyArgs);
  }

  async deleteUnique(id: string) {
    await this.prisma.agendaJob.delete({
      where: { id: id },
    });
    return { count: 1 };
  }

  async count(agendaJobCountArgs?: Prisma.AgendaJobCountArgs) {
    return await this.prisma.agendaJob.count(agendaJobCountArgs);
  }

  async groupBy(agendaJobGroupByArgs: Prisma.AgendaJobGroupByArgs) {
    return await this.prisma.agendaJob.groupBy(agendaJobGroupByArgs as any);
  }

  async aggregate(agendaJobAggregateArgs: Prisma.AgendaJobAggregateArgs) {
    return await this.prisma.agendaJob.aggregate(agendaJobAggregateArgs);
  }
}
