<?php

namespace Opencart\Extension\Alsendo\Providers;

require_once(DIR_EXTENSION . 'alsendo/src/Models/OrderShipmentPackage.php');
require_once(DIR_EXTENSION . 'alsendo/src/Repositories/OrderShipmentPackageRepository.php');

use Opencart\Extension\Alsendo\Models\OrderShipmentPackage;
use Opencart\Extension\Alsendo\Repositories\OrderShipmentPackageRepository;

class OrderShipmentPackageProvider
{
    private OrderShipmentPackageRepository $orderShipmentPackageRepository;

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

    /**
     * @deprecated
     */
    public function getByOrderShipmentId(int $orderShipmentId): ?OrderShipmentPackage
    {
        return $this->orderShipmentPackageRepository->getByOrderShipmentId($orderShipmentId);
    }

    /**
     * @return OrderShipmentPackage[]
     */
    public function getMultipleByOrderShipmentId(int $orderShipmentId): array {
        return $this->orderShipmentPackageRepository->getMultipleByOrderShipmentId($orderShipmentId);
    }

    public function getById(int $id): ?OrderShipmentPackage
    {
        return $this->orderShipmentPackageRepository->getById($id);
    }

    public function getData(int $orderShipmentId): array
    {
        $orderShipmentPackage = $this->orderShipmentPackageRepository->getByOrderShipmentId($orderShipmentId);
        
        if (!$orderShipmentPackage) {
            return [
                'exists' => false,
                'order_shipment_package' => null
            ];
        }

        return [
            'exists' => true,
            'order_shipment_package' => $orderShipmentPackage->toArray()
        ];
    }
}
