const orderService = require('../services/order.service');
const { OK, Created } = require('../core/success.response');

const orderController = {
    buyAccount: async (req, res) => {
        const userId = req.user.id;
        const { productId, discountCode } = req.body;
        const result = await orderService.buyProduct(userId, productId, discountCode);
        return new Created({
            message: 'Mua tài khoản thành công',
            metadata: result,
        }).send(res);
    },

    getHistory: async (req, res) => {
        const userId = req.user.id;
        const history = await orderService.getPurchaseHistory(userId);
        return new OK({
            message: 'Lấy lịch sử mua hàng thành công',
            metadata: history,
        }).send(res);
    },
};

module.exports = orderController;
