<?php

namespace Opencart\Catalog\Model\Extension\Alsendo\Module;

require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/OrderPickupPointEntity.php');

use Opencart\Extension\Alsendo\DTO\Entity\OrderPickupPointEntity;
use Opencart\System\Engine\Model;
use Opencart\System\Engine\Registry;

class AlsendoOrderPickupPoints extends Model {

    public function __construct(Registry $registry) {
        parent::__construct($registry);
    }

    public function getPickupPointByOrderId(int $orderId): ?OrderPickupPointEntity
    {
        $orderDetailsQuery = $this->db->query("
            SELECT *
            FROM `" . DB_PREFIX . "alsendo_order_pickup_points`
            WHERE order_id = '" . $orderId . "'
        ");

        if (!$orderDetailsQuery->num_rows) {
            return null;
        }

        return OrderPickupPointEntity::fromArray($orderDetailsQuery->row);
    }
}