<?php
require_once __DIR__ . '/../auth_middleware.php';
require_once '/home/akgbilis/fi_sf/config.php';

header('Content-Type: application/json');

// Giriş yapan kullanıcının ID'si
$userId = $decoded->sub;

// JSON girdiyi al
$input = json_decode(file_get_contents("php://input"), true);
$combineId = $input['combine_id'] ?? null;

if (!$combineId) {
    echo json_encode([
        "success" => false,
        "message" => "Missing combine_id"
    ]);
    exit;
}

// Sadece kullanıcının kendi oluşturduğu kuponu silsin
$stmt = $pdo->prepare("DELETE FROM user_generated_combines WHERE id = ? AND user_id = ?");
$success = $stmt->execute([$combineId, $userId]);

if ($success && $stmt->rowCount() > 0) {
    echo json_encode([
        "success" => true,
        "message" => "Coupon deleted successfully."
    ]);
} else {
    echo json_encode([
        "success" => false,
        "message" => "Coupon not found or not owned by user."
    ]);
}