import Thumbnail from "../../models/thumbnail-model";
import { ObjectId } from "mongodb";
import { IThumbnailDB } from "../dbTypes";

class ThumbnailDB implements IThumbnailDB {
  constructor() {}

  // READ

  getThumbnailInfo = async (userID: string, thumbnailID: string) => {
    const thumbnail = await Thumbnail.findOne({
      _id: new ObjectId(thumbnailID),
      owner: userID,
    });
    return thumbnail;
  };

  // DELETE

  removeThumbnail = async (userID: string, thumbnailID: ObjectId) => {
    const result = await Thumbnail.deleteOne({
      _id: thumbnailID,
      owner: userID,
    });
    return result;
  };

  // CREATE

  createThumbnail = async (data: {
    name: string;
    owner: string;
    IV: Buffer;
    path?: string;
    s3ID?: string;
  }) => {
    const thumbnail = new Thumbnail(data as any);
    await thumbnail.save();
    return thumbnail;
  };
}

export default ThumbnailDB;
