<?php

namespace App\Services;

use OpenAI;

class OpenAIService
{
    protected $client;

    public function __construct()
    {
        $this->client = OpenAI::client(env('OPENAI_API_KEY'));
    }

    public function ask($prompt)
    {
        $response = $this->client->chat()->create([
            'model' => 'gpt-5', // Bisa juga gpt-4o, gpt-4o-mini, dll
            'messages' => [
                ['role' => 'system', 'content' => 'You are a Laravel expert assistant.'],
                ['role' => 'user', 'content' => $prompt],
            ],
        ]);

        return $response->choices[0]->message->content;
    }
}
