<?php

declare(strict_types=1);

namespace App\Business\Sales;

use App\Models\DberpSalesOrder;
use App\Models\DberpSalesOutboundOrder;
use App\Support\DberpDocumentRemarkPropagation;

final class SalesReturnReferenceDefaultsResolver
{
    /**
     * @return array<string, int|string|null>
     */
    public function resolveFromSalesOrder(DberpSalesOrder $order): array
    {
        return [
            'customer_id' => (int) $order->customer_id,
            'handler_employee_id' => $order->handler_employee_id !== null ? (int) $order->handler_employee_id : null,
            'remark' => DberpDocumentRemarkPropagation::trimmedOrNull($order->remark),
        ];
    }

    /**
     * @return array<string, int|string|null>
     */
    public function resolveFromSalesOutbound(DberpSalesOutboundOrder $outbound): array
    {
        $defaults = [
            'sales_outbound_order_id' => (int) $outbound->getKey(),
            'customer_id' => (int) $outbound->customer_id,
            'handler_employee_id' => $outbound->handler_employee_id !== null ? (int) $outbound->handler_employee_id : null,
            'remark' => DberpDocumentRemarkPropagation::trimmedOrNull($outbound->remark),
        ];

        if ($outbound->sales_order_id !== null && (int) $outbound->sales_order_id > 0) {
            $defaults['sales_order_id'] = (int) $outbound->sales_order_id;
        }

        return $defaults;
    }
}
