<?php
declare(strict_types=1);

const YSP_VERSION_FILES = [
  'index.html',
  'api.php',
  '.htaccess',
  'assets/css/app.css',
  'assets/js/app.js',
];

function ysp_app_files(string $baseDir): array {
  $files = array_map(fn(string $path): string => $baseDir . '/' . $path, YSP_VERSION_FILES);
  foreach (glob($baseDir . '/.lib/*.php') ?: [] as $file) {
    $files[] = $file;
  }
  return array_values(array_unique($files));
}

function ysp_app_version(string $baseDir): string {
  $mtime = 0;
  foreach (ysp_app_files($baseDir) as $file) {
    if (is_file($file)) {
      $mtime = max($mtime, (int)filemtime($file));
    }
  }
  return (string)$mtime;
}
