import { Injectable } from '@nestjs/common';
import { BaseService } from '../base/base.service';
import {
  UserProfile,
  db,
  ObjectType,
  Prisma
} from '@nice/common';
import EventBus, { CrudOperation } from '@server/utils/event-bus';

@Injectable()
export class LectureService extends BaseService<Prisma.LectureDelegate> {
  constructor() {
    super(db, ObjectType.COURSE);
  }
  async create(args: Prisma.LectureCreateArgs, params?: { staff?: UserProfile }) {
    const result = await super.create(args)
    EventBus.emit('dataChanged', {
      type: ObjectType.LECTURE,
      operation: CrudOperation.CREATED,
      data: result,
    });
    return result;
  }
  async update(args: Prisma.LectureUpdateArgs) {
    const result = await super.update(args);
    EventBus.emit('dataChanged', {
      type: ObjectType.LECTURE,
      operation: CrudOperation.UPDATED,
      data: result,
    });
    return result;
  }

}
