<?php
require_once("../php/db_connect.php");

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

if (!isset($_SESSION["user_id"]) || ($_SESSION["role"] ?? "") !== "admin") {
    header("Location: index.php");
    exit();
}

$shop_id = (int)$_SESSION["user_id"];
$service_id = isset($_GET["id"]) ? (int)$_GET["id"] : 0;

if ($service_id <= 0) {
    header("Location: admin.php?page=archived-services&message=error");
    exit();
}

$stmt = $conn->prepare("
    UPDATE services
    SET status = 'active'
    WHERE id = ?
      AND owner_shop_id = ?
    LIMIT 1
");

$stmt->bind_param("ii", $service_id, $shop_id);

if ($stmt->execute()) {
    header("Location: admin.php?page=archived-services&message=restored");
    exit();
}

header("Location: admin.php?page=archived-services&message=error");
exit();