<?php
require_once '../../config.php';
require_once ROOT . 'app/db.php';

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

if (!$id) {
    header("Location: index.php");
    exit;
}

/* ===============================
   Bu apartmanda daire var mı?
   =============================== */
$daireSayisi = db::count("tb_daire", "WHERE apartmanID=?", [$id]);

if ($daireSayisi > 0) {
    // Daire varsa silme
    echo "<script>alert('Bu apartmanda daireler var, silemezsiniz!'); window.location='index.php';</script>";
    exit;
}

/* ===============================
   Apartmanı sil
   =============================== */
db::delete("tb_apartman", $id);

header("Location: index.php");
exit;
