import Supplier from "../models/Supplier.js";

export const createSupplier = async (req, res) => {
    try {
        const existing = await Supplier.findOne({ supplierCode: req.body.supplierCode });
        if (existing) return res.status(400).json({ message: "Supplier already exists" });

        const supplier = await Supplier.create(req.body);
        res.status(201).json(supplier);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};

export const getAllSuppliers = async (req, res) => {
    try {
        const suppliers = await Supplier.find();
        res.status(200).json(suppliers);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};