<?php

namespace OtomaticAi\Models\Presets;

use OtomaticAi\Api\XAi\Client as XAiClient;
use OtomaticAi\Api\XAi\PoolClient as PoolXAiClient;

class XAIPreset extends Preset
{
    /**
     * Create the xAI API payload
     *
     * @param array $params
     * @return array
     */
    public function payload(array $params = []): array
    {
        $model = $this->model;

        switch ($model) {
            case "grok-4":
                $model = "grok-4-0709";
            case "grok-4-fast":
                $model = "grok-4-fast-reasoning";
                break;
        }

        $payload = [
            "model" => $model,
            "stream" => false,
            "messages" => $this->replaceMessagesVariables($params),
        ];

        return $payload;
    }

    public function process(array $params = [])
    {
        $api = new XAiClient;
        return $api->chat($this->payload($params));
    }

    public function processPool(array $params = [])
    {
        $api = new PoolXAiClient;
        $params = array_map(function ($p) {
            return $this->payload($p);
        }, $params);
        return $api->chat($params);
    }
}
