<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * 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 com_eorisis_pixels\framework\install_package\lib\core\model;
\defined('_JEXEC') or die;

use com_eorisis_pixels\framework\install_package\lib\core\cms\application;
use com_eorisis_pixels\framework\install_package\lib\core\model\extension;
use com_eorisis_pixels\framework\install_package\lib\core\model\database;
use com_eorisis_pixels\framework\install_package\lib\core\model\params;
use com_eorisis_pixels\framework\install_package\lib\core\model\clean;

class component
{
	public function __construct() {}

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

	public static function get_auth_code() : string
	{
		$table_name = '#__'.extension::PACKAGE_NAME.'_sections';
		$dbo = application::dbo();
		$query = $dbo->getQuery(true);
		$query->select($dbo->quoteName('params'));
		$query->from($dbo->quoteName($table_name));
		$query->where($dbo->quoteName('name').'='.$dbo->quote('updates'));
		$dbo->setQuery($query);
		$result = database::get_first_result($dbo);
		if ($result['error'] or !isset($result['record']))
		{
			return '';
		}

		$item = (array)\json_decode((string)$result['record'], true);
		return clean::auth_code(params::get('auth_code', $item));
	}
}
