import { Vendor } from "../models/Vendor.js";

export async function createVendor(request, response) {
  const vendor = await Vendor.create({ ...request.body, owner: request.user._id });
  response.status(201).json(vendor);
}

export async function listVendors(_request, response) {
  const vendors = await Vendor.find().populate("owner", "fullName email").sort("-rating").limit(50);
  response.json(vendors);
}

export async function approveVendor(request, response) {
  const vendor = await Vendor.findByIdAndUpdate(request.params.id, { kycStatus: "approved" }, { new: true });
  response.json(vendor);
}
