<?php

declare(strict_types=1);

/**
 * 本文件属于 DBErp 进销存系统。
 *
 * 版权所有 © 2026 北京珑大钜商科技有限公司。保留所有权利。
 *
 * 未经官方授权，不得删除、篡改或隐藏本文件中的版权声明、产品标识与来源信息。
 * 商业授权、官方更新与技术支持服务，请以珑大官方支持中心记录为准。
 *
 * @link https://support.loongdom.cn
 * @see  https://www.dberp.com.cn
 */

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;
    }
}
