<?php
require_once 'tokenService.php';

class ShareService {

    private static string $projectRoot = '/temp5';
    private static string $defaultRoute = '/share/';

    public static function generarLink(
        string $modulo,
        string $title_id,
        int $id,
        string $ruta = null
    ): string {

        $ruta = $ruta ?? self::$defaultRoute;

        $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
        $host     = $_SERVER['HTTP_HOST'];

        $token = TokenService::generar([
            'modulo'   => $modulo,
            'title_id' => $title_id,
            'id'       => $id
        ]);

        return $protocol . '://' . $host . self::$projectRoot . $ruta . '?t=' . urlencode($token);
    }
}
