import { Inject, Injectable } from '@nestjs/common';
import { Prisma, WorkflowNodeType } 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 WorkflowNodeTypeService {
  constructor(
    private prisma: PrismaService,
    private readonly config: ConfigService,
    @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
  ) {}

  async createOne(
    workflowNodeTypeCreateArgs: Prisma.WorkflowNodeTypeCreateArgs,
  ) {
    return await this.prisma.workflowNodeType.create(
      workflowNodeTypeCreateArgs,
    );
  }

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

  async findMany(
    workflowNodeTypeFindManyArgs: Prisma.WorkflowNodeTypeFindManyArgs,
  ): Promise<{ itemCount: number; entities: WorkflowNodeType[] }> {
    const itemCount = await this.prisma.workflowNodeType.count({
      where: workflowNodeTypeFindManyArgs.where,
    });
    const entities = await this.prisma.workflowNodeType.findMany(
      workflowNodeTypeFindManyArgs,
    );
    return { itemCount, entities };
  }

  async findUnique(
    id: number,
    select: Prisma.WorkflowNodeTypeFindUniqueArgs['select'],
  ) {
    return await this.prisma.workflowNodeType.findUnique({
      where: { id: id },
      select,
    });
  }

  async updateMany(
    workflowNodeTypeUpdateManyArgs: Prisma.WorkflowNodeTypeUpdateManyArgs,
  ) {
    return await this.prisma.workflowNodeType.updateMany(
      workflowNodeTypeUpdateManyArgs,
    );
  }

  async updateUnique(
    id: number,
    data: Prisma.WorkflowNodeTypeUpdateManyArgs['data'],
  ) {
    return await this.prisma.workflowNodeType.update({
      where: { id: id },
      data,
    });
  }

  async deleteMany(
    workflowNodeTypeDeleteManyArgs: Prisma.WorkflowNodeTypeDeleteManyArgs,
  ) {
    return await this.prisma.workflowNodeType.deleteMany(
      workflowNodeTypeDeleteManyArgs,
    );
  }

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

  async count(workflowNodeTypeCountArgs?: Prisma.WorkflowNodeTypeCountArgs) {
    return await this.prisma.workflowNodeType.count(workflowNodeTypeCountArgs);
  }

  async groupBy(
    workflowNodeTypeGroupByArgs: Prisma.WorkflowNodeTypeGroupByArgs,
  ) {
    return await this.prisma.workflowNodeType.groupBy(
      workflowNodeTypeGroupByArgs as any,
    );
  }

  async aggregate(
    workflowNodeTypeAggregateArgs: Prisma.WorkflowNodeTypeAggregateArgs,
  ) {
    return await this.prisma.workflowNodeType.aggregate(
      workflowNodeTypeAggregateArgs,
    );
  }
}
