<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GuzzleHttp\Client;

class OpenRouterController extends Controller
{
    public function sendMessage(Request $request)
    {
        $client = new Client();
        
        $response = $client->post('https://openrouter.ai/api/v1/chat/completions', [
            'headers' => [
                'Authorization' => 'Bearer ' . env('OPENROUTER_API_KEY'),
                'Content-Type' => 'application/json',
            ],
            'json' => [
                'model' => 'openai/gpt-4o', 
                'messages' => [
                    ['role' => 'user', 'content' => $request->message]
                ]
            ]
        ]);

        $body = $response->getBody();
        $data = json_decode($body, true);

        return response()->json($data);
    }
}
