<?php
include "config.php";

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    exit("Invalid request");
}

$type = $_POST['type'] ?? null;

if ($type === "add") {

    $deposit = $_POST['deposit_amount'] ?? null;
    $bonus   = $_POST['bonus_amount'] ?? null;

    if ($deposit === null || $bonus === null) {
        exit("Missing parameters");
    }

    $stmt = $conn->prepare(
        "INSERT INTO deposits (deposit_amount, bonus_amount) VALUES (?, ?)"
    );

    if (!$stmt) {
        exit("Prepare failed");
    }

    $stmt->bind_param("ii", $deposit, $bonus);

    if ($stmt->execute()) {
        echo "Data added successfully";
    } else {
        echo "Insert failed";
    }

    $stmt->close();

} elseif ($type === "delete") {

    $id = $_POST['id'] ?? null;

    if ($id === null) {
        exit("Missing id");
    }

    $stmt = $conn->prepare(
        "DELETE FROM deposits WHERE id = ?"
    );

    if (!$stmt) {
        exit("Prepare failed");
    }

    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        echo "Data deleted successfully";
    } else {
        echo "Delete failed";
    }

    $stmt->close();

} else {
    exit("Invalid type");
}

$conn->close();
?>