const Joi = require('joi');
const Anime = require('../models/anime.model');

const animeSchema = Joi.object({
  animename: Joi.number().integer().required(),
  animetype: Joi.string().required(),
  animedetail: Joi.string().required(),
  //animeimage:Joi.string().required()
})


module.exports = {
  insert,
  get,
  getAll,
  search,
}

async function insert(anime) {
  anime = await Joi.validate(anime, animeSchema, { abortEarly: false });
  return await new Student(anime).save();
}

/**
 * อ่านเพิ่มเติม https://mongoosejs.com/docs/api.html
 */
async function get(sid) {
  return await Anime.find({sid: sid});
}

async function getAll() {
  return await Anime.find();
}

async function search(key, value) {
  let query = {};
  query[key] = value;
  return await Anime.find(query);
}
