<?php

declare(strict_types=1);

namespace KupShop\BalikonosBundle\BalikobotAdapters\B2A;

use KupShop\ReclamationsBundle\Entity\ReclamationEntity;
use KupShop\ReturnsBundle\Entity\ReturnEntity;

class BalikobotB2APPLAdapter implements IBalikobotB2AAdapter
{
    public function getDeliveryClassName(): string
    {
        return 'PPLReturnDelivery';
    }

    public function transformData(ReturnEntity|ReclamationEntity $entity, int $orderId, array $data): array
    {
        $order = new \Order();
        $order->createFromDB($orderId);

        $newData = [
            'rec_name' => $order->delivery_name,
            'rec_firm' => $order->delivery_firm,
            'rec_phone' => $order->delivery_phone ?: $order->invoice_phone,
            'rec_email' => $order->invoice_email,
            'rec_street' => $order->delivery_street,
            'rec_city' => $order->delivery_city,
            'rec_zip' => mb_strtoupper($order->delivery_zip),
            'rec_country' => $order->delivery_country,
            'service_type' => '45',
            'pieces_count' => 1,
            'real_order_id' => $order->order_no,
            'return_full_errors' => true,
        ];

        return array_merge($data, $newData);
    }

    public function getCarrierCode(): string
    {
        return 'ppl';
    }

    public function transformResponse(array $data): array
    {
        return $data;
    }
}
