<?php
/**
 * Tine 2.0
 *
 * @package     OnlyOfficeIntegrator
 * @subpackage  Config
 * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
 * @author      Cornelius Weiß <c.weiss@metaways.de>
 * @copyright   Copyright (c) 2019 Metaways Infosystems GmbH (http://www.metaways.de)
 */

/**
 * OnlyOfficeIntegrator config class
 *
 * @package     OnlyOfficeIntegrator
 * @subpackage  Config
 *
 */
class OnlyOfficeIntegrator_Config extends Tinebase_Config_Abstract
{
    const APP_NAME = 'OnlyOfficeIntegrator';

    const ONLYOFFICE_PUBLIC_URL = 'onlyOfficePublicUrl';
    const ONLYOFFICE_SERVER_URL = 'onlyOfficeServerUrl';
    const TINE20_SERVER_URL = 'tine20ServerUrl';
    const JWT_ENABLED = 'jwtEnabled';
    const JWT_SECRET = 'jwtSecret';
    const TOKEN_LIVE_TIME = 'tokenLiveTime';

    /**
     * (non-PHPdoc)
     * @see tine20/Tinebase/Config/Abstract::$_appName
     */
    protected $_appName = self::APP_NAME;

    /**
     * (non-PHPdoc)
     * @see tine20/Tinebase/Config/Definition::$_properties
     */
    protected static $_properties = [
        self::ONLYOFFICE_PUBLIC_URL => [
            //_('Public OnlyOffice document server url')
            self::LABEL                 => 'Public OnlyOffice document server url',
            //_('OnlyOffice document server url accessible by the users browser')
            self::DESCRIPTION           => 'OnlyOffice document server url accessible by the users browser',
            self::TYPE                  => self::TYPE_STRING,
            self::CLIENTREGISTRYINCLUDE => true,
            self::SETBYADMINMODULE      => false,
            self::SETBYSETUPMODULE      => true,
        ],
        self::ONLYOFFICE_SERVER_URL => [
            //_('Internal/Server OnlyOffice document server url')
            self::LABEL                 => 'Internal/Server OnlyOffice document server url',
            //_('OnlyOffice document server url accessible from this server. Leave empty if this is the same as the public url')
            self::DESCRIPTION           => 'OnlyOffice document server url accessible from this server. Leave empty if this is the same as the public url',
            self::TYPE                  => self::TYPE_STRING,
            self::CLIENTREGISTRYINCLUDE => true,
            self::SETBYADMINMODULE      => false,
            self::SETBYSETUPMODULE      => true,
        ],
        self::TINE20_SERVER_URL => [
            //_('Server url of this installation')
            self::LABEL                 => 'Server url of this installation',
            //_('Server url of this installation accessible by the OnlyOffice document server')
            self::DESCRIPTION           => 'Server url of this installation accessible by the OnlyOffice document server',
            self::TYPE                  => self::TYPE_STRING,
            self::CLIENTREGISTRYINCLUDE => false,
            self::SETBYADMINMODULE      => false,
            self::SETBYSETUPMODULE      => true,
        ],
        self::JWT_ENABLED => [
            //_('Enable oo jwt tokens')
            self::LABEL                 => 'Enable oo jwt tokens',
            //_('Enable tokens for browser requests corresponding to OnlyOffice JWT_ENABLED environment variable')
            self::DESCRIPTION           => 'Enable tokens for browser requests corresponding to OnlyOffice JWT_ENABLED environment variable',
            self::TYPE                  => self::TYPE_BOOL,
            self::CLIENTREGISTRYINCLUDE => true,
            self::SETBYADMINMODULE      => false,
            self::SETBYSETUPMODULE      => true,
        ],

        self::JWT_SECRET => [
            //_('OnlyOffice jwt secret string')
            self::LABEL                 => 'OnlyOffice inbox secret string',
            //_('OnlyOffice jwt secret string corresponding to OnlyOffice JWT_SECRET environment variable')
            self::DESCRIPTION           => 'OnlyOffice jwt secret string corresponding to OnlyOffice JWT_SECRET environment variable',
            self::TYPE                  => self::TYPE_STRING,
            self::CLIENTREGISTRYINCLUDE => false,
            self::SETBYADMINMODULE      => false,
            self::SETBYSETUPMODULE      => true,
        ],
        self::TOKEN_LIVE_TIME => [
            //_('Live time of token subscriptions')
            self::LABEL                 => 'Live time of token subscriptions',
            //_('Live time of token subscriptions')
            self::DESCRIPTION           => 'Live time of token subscriptions',
            self::TYPE                  => self::TYPE_INT,
            self::DEFAULT_STR           => 1200,
            self::CLIENTREGISTRYINCLUDE => true,
            self::SETBYADMINMODULE      => false,
            self::SETBYSETUPMODULE      => true,
        ],
    ];

    /**
     * holds the instance of the singleton
     *
     * @var OnlyOfficeIntegrator_Config
     */
    private static $_instance = NULL;

    /**
     * the constructor
     *
     * don't use the constructor. use the singleton
     */
    private function __construct()
    {
    }

    /**
     * the constructor
     *
     * don't use the constructor. use the singleton
     */
    private function __clone()
    {
    }

    /**
     * Returns instance of DFCom_Config
     *
     * @return OnlyOfficeIntegrator_Config
     */
    public static function getInstance()
    {
        if (self::$_instance === NULL) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

    /**
     * (non-PHPdoc)
     * @see tine20/Tinebase/Config/Abstract::getProperties()
     */
    public static function getProperties()
    {
        return self::$_properties;
    }
}
