import { Injectable } from '@nestjs/common';
import { BaseService } from '../base/base.service';
import {
  UserProfile,
  db,
  ObjectType,
  Prisma,
  Resource,
  ResourceStatus,
} from '@nice/common';

@Injectable()
export class ResourceService extends BaseService<Prisma.ResourceDelegate> {
  constructor() {
    super(db, ObjectType.RESOURCE);
  }
  async create(
    args: Prisma.ResourceCreateArgs,
    params?: { staff?: UserProfile },
  ): Promise<Resource> {
    if (params?.staff) {
      args.data.ownerId = params?.staff?.id;
    }
    return super.create(args);
  }
  async softDeleteByFileId(fileId: string) {
    return this.update({
      where: {
        fileId,
      },
      data: {
        deletedAt: new Date(),
      },
    });
  }
}
