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

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

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

$shop_id = isset($_GET["shop_id"]) ? (int)$_GET["shop_id"] : 0;
$service_type_id = isset($_GET["service_type_id"]) ? (int)$_GET["service_type_id"] : 0;

if ($shop_id <= 0 || $service_type_id <= 0) {
    echo json_encode([]);
    exit;
}

$stmt = $conn->prepare("
    SELECT subtype_name
    FROM service_subtype_options
    WHERE owner_shop_id = ?
      AND service_type_id = ?
      AND status = 'active'
    ORDER BY subtype_name ASC
");

if (!$stmt) {
    echo json_encode([]);
    exit;
}

$stmt->bind_param("ii", $shop_id, $service_type_id);
$stmt->execute();
$result = $stmt->get_result();

$subtypes = [];
while ($row = $result->fetch_assoc()) {
    $subtypes[] = $row;
}

echo json_encode($subtypes);
exit;
?>