<?php

namespace OtomaticAi\Models\Presets;

use OtomaticAi\Api\DeepSeek\Client as DeepSeekClient;
use OtomaticAi\Api\DeepSeek\PoolClient as PoolDeepSeekClient;

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

        $messages = $this->replaceMessagesVariables($params);

        $payload = [
            "model" => $model,
            "temperature" => $this->temperature ? intval($this->temperature) : 1,
            "top_p" => $this->top_p ? intval($this->top_p) : 1,
            "presence_penalty" => $this->presence_penalty ? round($this->presence_penalty, 2) : 0,
            "frequency_penalty" => $this->frequency_penalty ? round($this->frequency_penalty, 2) : 0,
            "n" => 1,
            "stream" => false,
            "messages" => $messages,
        ];

        return $payload;
    }

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

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

        return $api->chat($params);
    }
}
