<?php
require_once __DIR__ . '/config.php';

$conn = get_db_connection();

// 1. Ensure REPAIR category exists
$category_name = "REPAIR";
$category_slug = "repair";

$check_cat = $conn->prepare("SELECT id FROM service_categories WHERE slug = ?");
$check_cat->bind_param("s", $category_slug);
$check_cat->execute();
$res_cat = $check_cat->get_result();

if ($res_cat->num_rows > 0) {
    $row_cat = $res_cat->fetch_assoc();
    $category_id = $row_cat['id'];
    echo "Found existing REPAIR category with ID: $category_id\n";
} else {
    $ins_cat = $conn->prepare("INSERT INTO service_categories (name, slug, display_order) VALUES (?, ?, 6)");
    $ins_cat->bind_param("ss", $category_name, $category_slug);
    $ins_cat->execute();
    $category_id = $conn->insert_id;
    echo "Created new REPAIR category with ID: $category_id\n";
}

$repair_services = [
    [
        'name' => "Chimney Bricks Repair",
        'slug' => "chimney-bricks-repair",
        'description' => "Chimney bricks repair restores damaged or deteriorating bricks to maintain structural integrity and safety. Repairing cracked or loose bricks prevents water intrusion, reduces fire risk, and improves the overall appearance of your chimney. Professional brick repair ensures long-lasting results.",
        'content' => "<h3>What Is Chimney Bricks Repair?</h3><p>Chimney bricks repair is a specialized service that addresses damaged, cracked, or crumbling bricks in your chimney structure. Over time, exposure to weather, temperature fluctuations, and moisture can weaken bricks, compromising the chimney’s stability and safety.</p><p>Crest Chimney professionals carefully remove damaged bricks and replace them with high-quality masonry materials that match your existing chimney. The repair process ensures proper alignment, sealing, and structural support.</p><p>Timely brick repair prevents further deterioration, water infiltration, and potential chimney fires. This service restores the chimney’s structural integrity and prolongs its lifespan while maintaining aesthetic consistency with your home.</p>",
        'url' => "/our-services/chimney-bricks-repair/"
    ],
    [
        'name' => "Chimney Cap Repair",
        'slug' => "chimney-cap-repair",
        'description' => "Chimney cap repair fixes damaged or deteriorating caps to prevent water, animals, and debris from entering your chimney. A properly repaired cap improves safety, prevents leaks, and prolongs the life of your chimney system.",
        'content' => "<h3>What Is Chimney Cap Repair?</h3><p>Chimney cap repair addresses cracks, corrosion, or other damage to the protective cap installed at the top of your chimney. A damaged cap can allow water intrusion, animal entry, and debris accumulation.</p><p>Crest Chimney technicians repair or replace chimney caps with durable materials that restore protection and functionality. This process ensures your chimney is safeguarded against weather and pests.</p><p>Repairing a chimney cap prevents water damage, masonry deterioration, and reduces the risk of blockages and fire hazards.</p>",
        'url' => "/our-services/chimney-cap-repair/"
    ],
    [
        'name' => "Chimney Crown Repair",
        'slug' => "chimney-crown-repair",
        'description' => "Chimney crown repair restores the top concrete or masonry portion of your chimney, preventing water damage and structural deterioration. Timely repair keeps your chimney safe and weatherproof.",
        'content' => "<h3>What Is Chimney Crown Repair?</h3><p>Chimney crown repair focuses on the top portion of the chimney that seals the masonry and prevents water intrusion. Cracks or damage to the crown can lead to water penetration, rust, and masonry decay.</p><p>Crest Chimney experts repair or rebuild chimney crowns using durable materials, ensuring a watertight seal and long-lasting protection. This repair safeguards the chimney’s integrity and extends its lifespan.</p><p>Proper chimney crown maintenance prevents structural damage, mold growth, and deterioration of the chimney interior.</p>",
        'url' => "/our-services/chimney-crown-repair/"
    ],
    [
        'name' => "Chimney Damper Repair",
        'slug' => "chimney-damper-repair",
        'description' => "Chimney damper repair restores proper opening and closing function, improving energy efficiency and preventing drafts. A working damper keeps smoke, debris, and animals out while allowing safe venting of combustion gases.",
        'content' => "<h3>What Is Chimney Damper Repair?</h3><p>Chimney dampers control airflow from the fireplace into the chimney and prevent heat loss when the fireplace is not in use. Damaged or stuck dampers can cause drafts, smoke backflow, or energy inefficiency.</p><p>Crest Chimney technicians repair or replace dampers to ensure smooth operation and proper sealing. This repair restores full functionality, allowing your fireplace to operate safely and efficiently.</p><p>A properly functioning damper reduces energy loss, improves ventilation, and prevents unwanted debris or animals from entering your home through the chimney.</p>",
        'url' => "/our-services/chimney-damper-repair/"
    ],
    [
        'name' => "Chimney Flashing",
        'slug' => "chimney-flashing",
        'description' => "Chimney flashing repair prevents water leaks by sealing the joint between your chimney and roof. Proper flashing protects your home from water damage and maintains the structural integrity of your chimney.",
        'content' => "<h3>What Is Chimney Flashing?</h3><p>Chimney flashing consists of metal sheets installed around the base of the chimney where it meets the roof to prevent water intrusion. Damaged or improperly installed flashing can cause leaks and water damage.</p><p>Crest Chimney professionals repair or replace flashing using durable materials that provide a watertight seal. Proper installation protects the chimney and surrounding roofing structure.</p><p>Maintaining chimney flashing prevents leaks, structural damage, and costly repairs to both your chimney and home.</p>",
        'url' => "/our-services/chimney-flashing/"
    ],
    [
        'name' => "Chimney Flue Repair",
        'slug' => "chimney-flue-repair",
        'description' => "Chimney flue repair restores proper venting and eliminates leaks, cracks, or blockages. A repaired flue improves safety, reduces smoke damage, and prevents carbon monoxide hazards.",
        'content' => "<h3>What Is Chimney Flue Repair?</h3><p>The chimney flue channels smoke and gases safely out of your home. Cracks, gaps, or deterioration in the flue can cause smoke infiltration, reduced draft, or carbon monoxide hazards.</p><p>Crest Chimney experts repair flue liners or replace damaged sections to ensure proper venting and chimney safety. Repairs restore efficient airflow and prevent dangerous leaks.</p><p>Regular flue maintenance and repair improve fireplace performance and protect your home from fire and smoke risks.</p>",
        'url' => "/our-services/chimney-flue-repair/"
    ],
    [
        'name' => "Chimney Framing Repair",
        'slug' => "chimney-framing-repair",
        'description' => "Chimney framing repair restores the supporting structure around the chimney, ensuring stability and safety. Proper framing prevents structural shifts, settling, or damage to surrounding walls.",
        'content' => "<h3>What Is Chimney Framing Repair?</h3><p>Chimney framing repair focuses on the wooden or metal supports surrounding the chimney structure. Over time, framing can weaken due to age, moisture, or settling.</p><p>Crest Chimney technicians repair or reinforce chimney framing to restore structural integrity, ensuring the chimney remains stable and safely supported.</p><p>Proper framing repair prevents structural issues, protects surrounding walls, and maintains overall chimney safety.</p>",
        'url' => "/our-services/chimney-framing-repair/"
    ],
    [
        'name' => "Chimney Liner Repair",
        'slug' => "chimney-liner-repair",
        'description' => "Chimney liner repair restores the protective lining inside your chimney, preventing cracks, leaks, and fire hazards. A properly maintained liner ensures safe venting and improves efficiency.",
        'content' => "<h3>What Is Chimney Liner Repair?</h3><p>Chimney liners protect the masonry structure and safely direct smoke and gases out of your home. Damaged liners can lead to heat transfer, fires, or smoke leakage into living spaces.</p><p>Crest Chimney experts repair or replace liners using durable materials, restoring proper venting and structural protection.</p><p>Maintaining a sound chimney liner reduces fire risk, improves draft efficiency, and prolongs the life of your chimney.</p>",
        'url' => "/our-services/chimney-liner-repair/"
    ],
    [
        'name' => "Chimney Masonry Repair",
        'slug' => "chimney-masonry-repair",
        'description' => "Chimney masonry repair addresses cracks, loose mortar, or structural damage in your chimney’s brick or stonework. Professional masonry repair ensures durability, prevents leaks, and restores the chimney’s appearance.",
        'content' => "<h3>What Is Chimney Masonry Repair?</h3><p>Chimney masonry repair involves restoring brick, stone, or mortar that has deteriorated due to weather, age, or moisture. Cracked or loose masonry can compromise structural integrity and safety.</p><p>Crest Chimney professionals repair damaged masonry using high-quality materials and expert techniques to ensure a durable, long-lasting result.</p><p>Proper masonry repair prevents water damage, structural failure, and maintains the aesthetic appeal of your chimney.</p>",
        'url' => "/our-services/chimney-masonry-repair/"
    ],
    [
        'name' => "Chimney Repair",
        'slug' => "chimney-repair",
        'description' => "Comprehensive chimney repair addresses structural, masonry, and liner issues to restore safe operation. Timely repairs prevent fire hazards, water damage, and costly future repairs.",
        'content' => "<h3>What Is Chimney Repair?</h3><p>Chimney repair is a general service that covers structural, masonry, and liner issues affecting chimney safety and functionality. Problems like cracks, leaks, and deterioration can compromise performance and safety.</p><p>Crest Chimney technicians assess the entire chimney system and perform the necessary repairs to restore safety, durability, and efficiency.</p><p>Timely chimney repair reduces fire risk, prevents water damage, and ensures the chimney meets industry safety standards.</p>",
        'url' => "/our-services/chimney-repair/"
    ],
    [
        'name' => "Chimney Siding Repair",
        'slug' => "chimney-siding-repair",
        'description' => "Chimney siding repair restores exterior cladding to prevent moisture, rot, and damage. Proper siding repair improves curb appeal and protects your chimney structure.",
        'content' => "<h3>What Is Chimney Siding Repair?</h3><p>Chimney siding repair focuses on restoring exterior materials such as wood, vinyl, or metal that protect the chimney structure. Damaged siding can allow moisture and pests to compromise the chimney.</p><p>Crest Chimney experts repair or replace siding to ensure weatherproofing, durability, and visual consistency with your home.</p><p>Proper siding repair prevents water damage, rot, and structural issues, while maintaining the chimney’s appearance.</p>",
        'url' => "/our-services/chimney-siding-repair/"
    ],
    [
        'name' => "Chimney Tuckpointing",
        'slug' => "chimney-tuckpointing",
        'description' => "Chimney tuckpointing repairs damaged or eroded mortar joints between bricks, restoring strength and preventing water damage. Proper tuckpointing extends the chimney’s life and enhances appearance.",
        'content' => "<h3>What Is Chimney Tuckpointing?</h3><p>Chimney tuckpointing involves removing deteriorated mortar between bricks and replacing it with fresh, durable mortar. Over time, mortar can erode due to weather and temperature changes.</p><p>Crest Chimney professionals perform precise tuckpointing to maintain structural integrity and prevent water infiltration.</p><p>Proper tuckpointing improves chimney safety, longevity, and aesthetics.</p>",
        'url' => "/our-services/chimney-tuckpointing/"
    ],
    [
        'name' => "Downdraft Repair",
        'slug' => "downdraft-repair",
        'description' => "Downdraft repair corrects smoke and airflow issues caused by negative pressure in your chimney. Fixing downdrafts ensures smoke is properly vented and prevents indoor air quality problems.",
        'content' => "<h3>What Is Downdraft Repair?</h3><p>Downdraft repair addresses issues where smoke reverses direction and enters the home instead of exiting through the chimney. This can be caused by negative pressure, improper venting, or structural issues.</p><p>Crest Chimney technicians diagnose the cause and implement solutions to restore proper airflow, improving safety and comfort.</p><p>Repairing downdrafts prevents smoke inhalation, reduces fire hazards, and ensures efficient fireplace operation.</p>",
        'url' => "/our-services/downdraft-repair/"
    ],
    [
        'name' => "Electric Fireplace Repair",
        'slug' => "electric-fireplace-repair",
        'description' => "Electric fireplace repair restores functionality, safety, and efficiency to your electric heating system. Repairs address electrical, mechanical, or aesthetic issues for reliable operation.",
        'content' => "<h3>What Is Electric Fireplace Repair?</h3><p>Electric fireplace repair involves diagnosing and fixing issues with the electrical, mechanical, or visual components of your fireplace. Common problems include faulty wiring, heater malfunctions, and damaged controls.</p><p>Crest Chimney technicians perform repairs to restore safe operation, improve efficiency, and maintain the fireplace’s aesthetic appearance.</p><p>Professional repair ensures a reliable and safe heating experience with your electric fireplace.</p>",
        'url' => "/our-services/electric-fireplace-repair/"
    ],
    [
        'name' => "Fireplace Gas Valve Repair",
        'slug' => "fireplace-gas-valve-repair",
        'description' => "Fireplace gas valve repair ensures safe and efficient operation of your gas fireplace by fixing leaks, faulty valves, or pressure issues. Professional repair prevents hazards and restores performance.",
        'content' => "<h3>What Is Fireplace Gas Valve Repair?</h3><p>Fireplace gas valve repair focuses on maintaining proper gas flow, sealing, and pressure in your gas fireplace system. Malfunctioning valves can cause leaks, inefficient combustion, or safety hazards.</p><p>Crest Chimney technicians inspect, repair, or replace faulty valves to restore safe and efficient operation.</p><p>Timely gas valve repair reduces fire and carbon monoxide risks and ensures reliable performance.</p>",
        'url' => "/our-services/fireplace-gas-valve-repair/"
    ],
    [
        'name' => "Fireplace Masonry Repair",
        'slug' => "fireplace-masonry-repair",
        'description' => "Fireplace masonry repair restores damaged bricks, stone, or mortar in your fireplace. This repair improves safety, prevents structural issues, and maintains the appearance of your fireplace.",
        'content' => "<h3>What Is Fireplace Masonry Repair?</h3><p>Fireplace masonry repair addresses deterioration or damage in the firebox or surrounding masonry. Cracks or loose bricks can lead to heat loss, smoke leakage, or structural failure.</p><p>Crest Chimney professionals repair and reinforce masonry to restore safety, durability, and visual appeal.</p><p>Proper masonry repair ensures safe operation and extends the lifespan of your fireplace.</p>",
        'url' => "/our-services/fireplace-masonry-repair/"
    ],
    [
        'name' => "Fireplace Panels Repair",
        'slug' => "fireplace-panels-repair",
        'description' => "Fireplace panels repair fixes broken, damaged, or worn panels to restore safety and appearance. Professional repair ensures proper heat containment and smooth operation.",
        'content' => "<h3>What Is Fireplace Panels Repair?</h3><p>Fireplace panels repair involves replacing or fixing damaged panels that line your fireplace or firebox. These panels protect surrounding materials from heat and maintain proper containment of flames.</p><p>Crest Chimney technicians repair or replace panels to restore safe operation and aesthetic consistency.</p><p>Timely panel repair ensures safety, efficiency, and prolongs the life of your fireplace.</p>",
        'url' => "/our-services/fireplace-panels-repair/"
    ],
    [
        'name' => "Gas Fireplace Repair",
        'slug' => "gas-fireplace-repair",
        'description' => "Gas fireplace repair restores proper function, efficiency, and safety to your gas fireplace. Repairs may include gas lines, burners, valves, and ignition systems.",
        'content' => "<h3>What Is Gas Fireplace Repair?</h3><p>Gas fireplace repair addresses issues with burners, gas lines, ignition, or control systems that affect performance or safety. Malfunctions can lead to poor heating, gas leaks, or fire hazards.</p><p>Crest Chimney professionals diagnose and repair all components, ensuring safe and reliable operation.</p><p>Regular maintenance and repair improve safety, efficiency, and comfort.</p>",
        'url' => "/our-services/gas-fireplace-repair/"
    ],
    [
        'name' => "Pellet Stove Repair",
        'slug' => "pellet-stove-repair",
        'description' => "Pellet stove repair restores the mechanical and electrical components of your stove, ensuring safe and efficient heating. Repairs prevent malfunctions and extend the lifespan of your appliance.",
        'content' => "<h3>What Is Pellet Stove Repair?</h3><p>Pellet stove repair involves fixing mechanical, electrical, and fuel delivery issues that affect operation. Problems may include auger jams, motor failures, or igniter malfunctions.</p><p>Crest Chimney technicians perform comprehensive repairs to restore safe and efficient heating.</p><p>Professional pellet stove repair prolongs appliance life, improves performance, and ensures safety.</p>",
        'url' => "/our-services/pellet-stove-repair/"
    ],
    [
        'name' => "Smoke Chamber Repair",
        'slug' => "smoke-chamber-repair",
        'description' => "Smoke chamber repair restores the area above your fireplace, improving draft and preventing smoke backup. Professional repair reduces fire hazards and improves ventilation.",
        'content' => "<h3>What Is Smoke Chamber Repair?</h3><p>Smoke chamber repair focuses on the area between the firebox and the flue. Over time, this area can become damaged or soot-filled, leading to poor draft and potential fire risks.</p><p>Crest Chimney experts repair and seal smoke chambers to ensure smooth airflow and safe operation.</p><p>Proper smoke chamber repair improves fireplace efficiency and safety.</p>",
        'url' => "/our-services/smoke-chamber-repair/"
    ]
];

$stmt = $conn->prepare("INSERT INTO services (name, category_id, slug, description, content, url) VALUES (?, ?, ?, ?, ?, ?)");

foreach ($repair_services as $service) {
    // Check if service already exists
    $check = $conn->prepare("SELECT id FROM services WHERE slug = ?");
    $check->bind_param("s", $service['slug']);
    $check->execute();
    if ($check->get_result()->num_rows > 0) {
        echo "Service '{$service['name']}' already exists. Skipping.\n";
        continue;
    }

    $stmt->bind_param(
        "sissss",
        $service['name'],
        $category_id,
        $service['slug'],
        $service['description'],
        $service['content'],
        $service['url']
    );

    if ($stmt->execute()) {
        echo "Inserted service: {$service['name']}\n";
    } else {
        echo "Error inserting service '{$service['name']}': " . $stmt->error . "\n";
    }
}

echo "Done.\n";
