<?php
/**
 * Shipment COD Service.
 *
 * @package   NovaPostForWoocommerce
 */

namespace NovaPostForWoocommerce\Services;

use NovaPostForWoocommerce\Models\NovaPostSettings;

/**
 * Class ShipmentCodService.
 */
class ShipmentCodService {

    /**
     * Method to prepare COD data.
     *
     * @param mixed            $order WooCommerce Order.
     * @param NovaPostSettings $settings Nova Post settings.
     * @return array
     */
    public static function prepare_cod_data( $order, NovaPostSettings $settings ) {
        return array(
            'shipmentParcelRowNumber' => null,
            'serviceCode'             => 'COD',
            'amount'                  => floatval( round( $order->get_total() - $order->get_shipping_total(), 2 ) ),
            'contractNumber'          => null,
            'payerType'               => 'Recipient',
            'additionalParameters'    => array(
                'cod' => array(
                    'cash'        => null,
                    'card'        => null,
                    'bankAccount' => array(
                        'amount'          => floatval( round( $order->get_total() - $order->get_shipping_total(), 2 ) ),
                        'currencyCode'    => $order->get_currency(),
                        'bankAccountId'   => $settings->cod_bank_account_id,
                        'bankAccountName' => $settings->cod_bank_account_name,
                        'description'     => 'Order Id: ' . $order->get_order_number(),
                        'commissionPayer' => $settings->cod_fee_paid_seller ? 'Sender' : 'Recipient',
                    ),
                ),
            ),
        );
    }
}
