<?php

namespace Opencart\Extension\Alsendo\Handlers;

use Opencart\Extension\Alsendo\Services\WrapperService;

class OrderShipmentHandler
{
    private WrapperService $wrapperService;

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

    public function estimateShipment(array $data): array
    {
        $validationResult = $this->validateShipmentData($data);
        if (!$validationResult['valid']) {
            return [
                'success' => false,
                'error' => $validationResult['error']
            ];
        }

        return [
            'success' => true,
            'data' => $data
        ];
    }

    private function validateShipmentData(array $data): array
    {
        if (isset($data['pickup_hour_from']) && isset($data['pickup_hour_to'])) {
            $from = (int)substr($data['pickup_hour_from'], 0, 2);
            $to = (int)substr($data['pickup_hour_to'], 0, 2);
            
            if ($to - $from < 2) {
                return [
                    'valid' => false,
                    'error' => 'error_pickup_hours_range'
                ];
            }
            
            if ($from >= $to) {
                return [
                    'valid' => false,
                    'error' => 'error_pickup_hours_order'
                ];
            }
        }

        return ['valid' => true];
    }
} 