<?php

declare(strict_types=1);

namespace App\Models;

/**
 * Result of POST /karvipartner/contracts/{contract_id}/send (Send contract API).
 */
final class ContractSendResult
{
    public function __construct(
        public readonly bool $success,
        public readonly string $message,
        public readonly string $signUrl = '',
        public readonly string $signToken = '',
        public readonly ?array $apiResponse = null,
        public readonly int $httpStatus = 0,
        public readonly ?string $errorCode = null,
    ) {
    }

    public static function ok(
        string $message,
        string $signUrl,
        string $signToken,
        array $apiResponse,
        int $httpStatus = 200
    ): self {
        return new self(
            success: true,
            message: $message,
            signUrl: $signUrl,
            signToken: $signToken,
            apiResponse: $apiResponse,
            httpStatus: $httpStatus,
        );
    }

    /** @param array<string,mixed>|null $apiResponse */
    public static function fail(
        string $message,
        ?array $apiResponse = null,
        int $httpStatus = 400,
        ?string $errorCode = null
    ): self {
        return new self(
            success: false,
            message: $message,
            apiResponse: $apiResponse,
            httpStatus: $httpStatus,
            errorCode: $errorCode,
        );
    }
}
