<?php

namespace App\Services\Integrations\Discovery;

class AccountDiscoveryResult
{
    /**
     * @param array<int, array<string, mixed>> $accounts
     * @param array<string, mixed> $meta
     */
    public function __construct(
        public readonly bool $ok,
        public readonly string $message,
        public readonly array $accounts = [],
        public readonly array $meta = [],
        public readonly ?int $statusCode = null,
    ) {}

    /**
     * @param array<int, array<string, mixed>> $accounts
     * @param array<string, mixed> $meta
     */
    public static function success(string $message, array $accounts = [], array $meta = [], ?int $statusCode = null): self
    {
        return new self(true, $message, $accounts, $meta, $statusCode);
    }

    /**
     * @param array<string, mixed> $meta
     */
    public static function failed(string $message, array $meta = [], ?int $statusCode = null): self
    {
        return new self(false, $message, [], $meta, $statusCode);
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'ok' => $this->ok,
            'message' => $this->message,
            'accounts' => $this->accounts,
            'meta' => $this->meta,
            'status_code' => $this->statusCode,
        ];
    }
}
