<?php
class OrderController {
    private $orderModel;

    public function __construct($orderModel) {
        $this->orderModel = $orderModel;
    }

    public function getOrdersByUserId($userId) {
        $this->deleteOrdersWithZeroQuantity($userId);
        return $this->orderModel->getOrdersByUserId($userId);
    }

    public function deleteOrdersWithZeroQuantity($userId) {
        $this->orderModel->deleteOrdersWithZeroQuantity($userId);
    }

    public function sell($userId, $itemId, $quantityToSell) {
        return $this->orderModel->sellItem($userId, $itemId, $quantityToSell);
    }

    public function return($userId, $itemId, $quantityToReturn) {
        return $this->orderModel->returnItem($userId, $itemId, $quantityToReturn);
    }

    public function resetOrders($userId) {
        return $this->orderModel->resetUserOrders($userId);
    }

    public function hasUnconfirmedClearance($userId) {
        return $this->orderModel->hasUnconfirmedClearance($userId);
    }

    public function finalizeDeal($itemIds) {
        $userId = $_SESSION['user_id'];
        return $this->orderModel->finalizeDeal($userId, $itemIds);
    }
}
?>
