package com.example.boidelov3;

//public class ChatGPTTask extends AsyncTask<Void, Void, String> {
////    private Jeux jeuxActivity;
////    private String keyOpenai;
////
////    public ChatGPTTask(Jeux jeuxActivity, String keyOpenai) {
////        this.jeuxActivity = jeuxActivity;
////        this.keyOpenai = keyOpenai;
////    }
////
////
////    @Override
////    protected String doInBackground(Void... voids) {
////        String url = "https://api.openai.com/v1/chat/completions";
////        String apiKey = keyOpenai;
////        System.out.println("apiKey de ChatGPTTASK.java: " + apiKey);
////        String model = "gpt-3.5-turbo";
////
////        String prompt = "Tu es une IA française qui génère des questions ainsi que la categories de la question. Voici des exemples :" +
////                "Celles/Ceux qui ont habité dans plus de 3 villes diferentes';'La vie" +
////                "Ceux qui ont dansé aujourd'hui' ; 'Soirée'" +
////                "'Pour se décoincer, le/la plus timide' ; 'Caractère'" +
////                "'Celles et ceux qui ont déjà dépenser plus de 2000 euros en un achat' ; 'Dépense'" +
////                "'Le/La plus radin(e)' ; 'Caractère'";
//
////        try {
////            URL obj = new URL(url);
////            HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
////            connection.setRequestMethod("POST");
////            connection.setRequestProperty("Authorization", "Bearer " + apiKey);
////            connection.setRequestProperty("Content-Type", "application/json");
////
////            // The request body
////            String body = "{\"model\": \"" + model + "\", \"messages\": [{\"role\": \"user\", \"content\": \"" + prompt + "\"}]}";
////            System.out.println("body: " + body);
////            connection.setDoOutput(true);
////            OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
////            writer.write(body);
////            writer.flush();
////            writer.close();
////
////            // Response from ChatGPT
////            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
////            String line;
////
////            StringBuffer response = new StringBuffer();
////
////            while ((line = br.readLine()) != null) {
////                response.append(line);
////            }
////            br.close();
////
////            // calls the method to extract the message.
////            return extractMessageFromJSONResponse(response.toString());
////
////        } catch (IOException e) {
////            System.out.println("Il y a eu une erreur" + e);
////            throw new RuntimeException(e);
////
////        }
////    }
////
////    public String extractMessageFromJSONResponse(String response) {
////        int start = response.indexOf("content") + 11;
////        int end = response.indexOf("\"", start);
////        String extractedMessage = response.substring(start, end);
////        System.out.println("extractedMessage: " + extractedMessage);
////        return extractedMessage;
////    }
////
////    @Override
////    protected void onPostExecute(String result) {
////        if (result != null) {
////            // Handle the extracted message here
////            jeuxActivity.handleExtractedMessage(result);
////        } else {
////            Toast.makeText(jeuxActivity.getApplicationContext(), "Échec de la communication avec l'API !", Toast.LENGTH_SHORT).show();
////            jeuxActivity.navigateToJeuxParametres();
////        }
////    }
//
//
//        return url;
//    }}