<?php
session_start();
include '../config/database.php';

// Pastikan hanya admin yang bisa akses
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $gemini = mysqli_real_escape_string($conn, $_POST['gemini_api_key']);
    $groq1  = mysqli_real_escape_string($conn, $_POST['groq_api_key']);
    $groq2  = mysqli_real_escape_string($conn, $_POST['groq_api_key_2']);
    $groq3  = mysqli_real_escape_string($conn, $_POST['groq_api_key_3']);
    $groq4  = mysqli_real_escape_string($conn, $_POST['groq_api_key_4']);

    $sql = "UPDATE settings SET 
            gemini_api_key = '$gemini', 
            groq_api_key = '$groq1', 
            groq_api_key_2 = '$groq2', 
            groq_api_key_3 = '$groq3', 
            groq_api_key_4 = '$groq4' 
            WHERE id = 1";

    if(mysqli_query($conn, $sql)){
        header("Location: konfigurasi.php?status=success");
    } else {
        echo "Error updating record: " . mysqli_error($conn);
    }
}