<?php

namespace App\Services;

use Openguru\OpenCartFramework\QueryBuilder\Connections\ConnectionInterface;

class OrderMetaService
{
    private ConnectionInterface $connection;

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

    public function insert(int $orderId, int $storeId, array $fields, ?int $telecartCustomerId = null): void
    {
        $orderMeta = [
            'oc_order_id' => $orderId,
            'oc_store_id' => $storeId,
            'telecart_customer_id' => $telecartCustomerId,
            'meta_data' => json_encode($fields, JSON_THROW_ON_ERROR),
        ];

        $this->connection->insert('telecart_order_meta', $orderMeta);
    }
}
