<?php
/*
 * Software Name: Eorisis Setup
 * Software URI: https://eorisis.com/shop/software/joomla/setup
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace eorisis_setup\framework\lib\core\model;
\defined('_JEXEC') or die;

class headers
{
	public function __construct() {}

	// --------------------------------------------------

	public static function get(array $extension, array $headers) : array
	{
		// $extension contains: type, element, folder, client

		$useragent = \eorisis_setup\framework\lib\core\app\config::USER_AGENT;
		$timestamp = \microtime(true);
		$update = \eorisis_setup\framework\lib\core\model\auth::get_update_data($extension['type'], $extension['element'], $extension['folder']);

		if ($update['auth_code'])
		{
			$auth_code = \hash('sha256', $timestamp.$useragent.$update['auth_code'].$extension['element'].$extension['type']);
		}
		else
		{
			$auth_code = '';
		}

		$headers['X-Download-Platform'] = 'joomla';
		$headers['X-Download-JVERSION'] = JVERSION;
		$headers['X-Download-PHP-VERSION'] = PHP_VERSION;
		$headers['X-Download-Host'] = \eorisis_setup\framework\lib\core\controller\request::server_hostname();
		$headers['X-Download-Type'] = $extension['type'];
		$headers['X-Download-Element'] = $extension['element'];
		$headers['X-Download-Edition'] = $update['edition'];
		$headers['X-Download-Auth-Code'] = $auth_code;
		$headers['X-Download-User-Agent'] = $useragent;
		$headers['X-Download-Time'] = $timestamp;
		$headers['X-Download-Algorithm'] = 'sha256';
		$headers['User-Agent'] = $useragent;
		$headers['Accept-Encoding'] = 'identity';
		$headers['Cache-Control'] = 'no-cache, no-store, no-transform, private, must-revalidate, proxy-revalidate, max-age=0, s-maxage=0';
		return $headers;
	}
}
