const { Drivers } = require('../../models');

exports.createDrivers = async (req, res, next) => {
	try {
		const { email, password } = req.body;

		if (!email || !password) {
			return res.status(400).json({ success: false, message: 'Email and password are required' });
		}

		const existingDriver = await Drivers.findOne({ where: { email_address: email } });
		if (existingDriver) {
			return res.status(400).json({ success: false, message: 'Driver with this email already exists' });
		}
		const driver = await Drivers.create({
			email_address: email,
			password,
		});

		return res.status(201).json({
			success: true,
			message: 'Driver created successfully',
			driver,
		});
	} catch (error) {
		next(error);
	}
};
