<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require 'functions.php';
require 'db_connect.php'; // This already sets $conn

$api_key = 'AIzaSyBAON_ChCgF5BEXX7ijp--GImeRmAHdUBY';

// Get current date and time in readable format
$currentTime = date('Y-m-d H:i:s');

echo "<h3>Sync started at: $currentTime</h3>";

// -----------------------------
// Teledramas Sync
// -----------------------------
$startTeledrama = date('Y-m-d H:i:s');
echo "<p>Teledrama sync started at: $startTeledrama</p>";

$totalUpdated = updateTeledramasAndEpisodes($conn, $api_key, 0);

$endTeledrama = date('Y-m-d H:i:s');
echo "<p>Teledrama sync completed at: $endTeledrama</p>";
echo "<p>Total teledramas updated: $totalUpdated</p><hr>";

// -----------------------------
// Programmes Sync
// -----------------------------
$startProgramme = date('Y-m-d H:i:s');
echo "<p>Programme sync started at: $startProgramme</p>";

$totalUpdated = updateProgrammesAndEpisodes($conn, $api_key, 0);

$endProgramme = date('Y-m-d H:i:s');
echo "<p>Programme sync completed at: $endProgramme</p>";
echo "<p>Total programmes updated: $totalUpdated</p>";

$finished = date('Y-m-d H:i:s');
echo "<h3>All syncs finished at: $finished</h3>";
?>
