<?php

namespace ZenoChatbot\Services\LLMService\Contracts;

use ZenoChatbot\Framework\Support\Arr;

/**
 * LLMResponse
 *
 * Standardizes a response format for LLM providers.
 * Centralizes commonly shared response data like success, message, tokens used, provider, and model.
 * Providers can prefer this over creating custom response formats, improving consistency and testability.
 *
 * @property bool $success
 * @property string $message
 * @property int $tokens_used
 * @property string $provider
 * @property string $model
 * @property string $error
 * @property array $raw_response
 */

if (!defined('ABSPATH')) exit;

class LLMResponse
{
    protected $response = [
        'success'     => false,
        'response'    => '',
        'tokens_used' => 0,
        'provider'    => '',
        'model'       => '',
    ];

    public function __construct($response = [])
    {
        $this->response = wp_parse_args($response, $this->response);
    }

    public function __get($name)
    {
        return Arr::get($this->response, $name);
    }

    public static function createFromArray($data = [])
    {
        return new static($data);
    }

    public function toArray()
    {
        return $this->response;
    }
}
