<?php

namespace App\Modules\Integrations\Platform\Support;

final class ApiErrorResponse
{
    public function __construct(
        public readonly string $code,
        public readonly string $message,
        /** @var array<string, mixed>|null */
        public readonly ?array $details = null,
    ) {}

    /**
     * @return array{code:string,message:string,details?:array<string,mixed>}
     */
    public function toArray(): array
    {
        $payload = [
            'code' => $this->code,
            'message' => $this->message,
        ];

        if ($this->details !== null) {
            $payload['details'] = $this->details;
        }

        return $payload;
    }
}

