<?php

namespace App\Services\Wallet;

use App\Models\TransferOrder;

/**
 * 调用主站钱包 HTTP 后的统一结果（转入扣主站 / 转出加主站）。
 */
final readonly class MainSiteWalletResult
{
    public function __construct(
        public bool $ok,
        public ?string $externalRefNo,
        /** @var array<string, mixed>|null */
        public ?array $responsePayload,
        /** 发往主站的 JSON 请求体快照，写入 {@see TransferOrder::external_request_payload} */
        public ?array $requestPayload,
        public ?string $errorMessage,
        /**
         * 网络超时/连接类不确定结果：由 {@see HttpMainSiteWalletGateway} 设置，上层将订单标为 pending_reconcile，
         * 不重复扣加款（PRD §6.2 / §6.7）。
         */
        public bool $uncertain = false,
    ) {}

    public static function success(?string $ref, ?array $payload = null, ?array $requestPayload = null): self
    {
        return new self(true, $ref, $payload, $requestPayload, null, false);
    }

    public static function failure(string $message, ?array $payload = null, bool $uncertain = false, ?array $requestPayload = null): self
    {
        return new self(false, null, $payload, $requestPayload, $message, $uncertain);
    }
}
