<?php

$PROJECT_TITLE = 'Webgallery';

$WEB_URL = 'https://www.mschwab.net';
$IMMICH_URL = 'https://immich.mschwab.net';
$IMMICH_API_KEY  = '5lm5xdIcSeGdNY6sOYljV1Am8BqB3Bbqe19PUcIkzzo';

function immichRequest($url) {
  global $IMMICH_API_KEY;
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "x-api-key: $IMMICH_API_KEY",
    "Content-Type: application/json"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  return json_decode($response, true);
}

function logData(string $message, ?array $data = null) {
  $logDir = '../logs';
  $today = date('Y-m-d');
  $now = date('Y-m-d H:i:s');

  $date = new DateTime("now", new DateTimeZone('Europe/Zurich')); 

  if (!is_dir($logDir)) {
    mkdir($logDir, 0777, true);
  }
  $logFile = $logDir . '/log-' . $date->format('Y-m-d') . '.log';

  $logData = '[' . $date->format('Y-m-d H:i:s') . ']' . ' - ' . $message . "\n";

  if ($data) {
    $dataString = print_r($data, true) . "\n";
    $logData .= $dataString;
  }

  file_put_contents($logFile, $logData, FILE_APPEND);
}