const Booking = require("../../models/booking");

exports.addbooking = async (req, res) => {
  try {
    const addbookingData = req.body;
    console.log(addbookingData);
    await Booking.create(addbookingData);
    res.send("create");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};

exports.getBooking = async (req, res) => {
  try {
    let booking = await Booking.findAll();
    res.status(200).send("booking");
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};
exports.getBookingShopid = async (req, res) => {
  try {
    const shop = req.params.shop;
    let booking = await Booking.findAll({
      where: {
        shop: shop,
      },
    });
    res.status(200).send(booking);
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};

exports.getBookingDate = async (req, res) => {
  try {
    const date = req.params.date;
    let booking = await Booking.findAll({
      where: {
        date: date,
      },
    });
    res.status(200).send(booking);
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};
exports.searchBooking= async (req, res) => {
  const date = req.body.date;
  console.log("name", name);

  if (name !== undefined) {
    console.log("called1");
    var condition = name ? { name: { [Op.like]: `%${name}%` } } : null;
    const datasearch = await Booking.findAll({
      where: condition,
    });
    res.status(200).send(datasearch);
  } else {
    console.log("called2");

    const datasearch = await  Booking.findAll({
     
    });
    res.status(200).send(datasearch);
  }
};
exports.getBookingbeautician = async (req, res) => {
  try {
    const beautician= req.params.beautician;
    let booking = await Booking.findAll({
      where: {
        beautician: beautician,
      },
    });
    res.status(200).send(booking);
  } catch (err) {
    console.log(err);
    res.sendStatus(401);
  }
};
