<?php

namespace XZD\AI\V5\AI\Providers;

use XZD\AI\V5\AI\OpenAICompatibleProvider;

/**
 * Xiaomi MiMo provider.
 *
 * @see https://mimo.mi.com/docs/zh-CN/quick-start/summary/welcome
 */
class MiMoProvider extends OpenAICompatibleProvider
{
    public static function defaultBaseUrl(): string
    {
        return 'https://api.xiaomimimo.com/v1';
    }

    public static function defaultModel(): string
    {
        return 'mimo-v2-flash';
    }

    public function getProviderKey(): string
    {
        return 'mimo';
    }

    /**
     * @return array
     */
    protected function buildHeaders(): array
    {
        return [
            'api-key'      => $this->config['api_key'],
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ];
    }

    /**
     * @param array $messages
     * @param array $options
     * @param bool  $stream
     * @return array
     */
    protected function buildRequestBody(array $messages, array $options, bool $stream): array
    {
        $body = parent::buildRequestBody($messages, $options, $stream);
        $model = $this->config['model'] ?: static::defaultModel();
        // flash 系列不支持推理模式，pro/omni 支持
        if (stripos($model, 'flash') !== false || stripos($model, 'tts') !== false) {
            unset($body['thinking']);
        }
        return $body;
    }
}
