#ifndef KEYZY_LICENSE_VALIDATOR_H
#define KEYZY_LICENSE_VALIDATOR_H

#include "KeyzyTypes.h"

namespace vk
{
    class AuthSys2;
}

namespace Keyzy
{
    class KeyzyLicenseProvider;

    /*!
    * KeyzyLicenseValidator class should be used to validate licenses available on a client machine.
    */
    class KeyzyLicenseValidator
    {
    public:
        /*!
        * Create an instance of KeyzyLicenseValidator that will validate licenses for a product defined in ProductData structure
        * @param productData Structure that describes a product for which going to validate available licenses
        * @param licenseProvider is for not to create multiple object to prevent when update the license, update the provider
        */
        KeyzyLicenseValidator(std::shared_ptr<KeyzyLicenseProvider> licenseProvider);
        ~KeyzyLicenseValidator();

        /*!
         * Validate license online for product specified in KeyzyLicenseValidator constructor.
         * Sends the stored serial number to the KEYZY server for validation.
         * Works for all license types: perpetual, subscription and server-side trial.
         * @return License status
         */
        LicenseStatus validateOnline() noexcept;

        /*!
         * Validate license offline for product specified in KeyzyLicenseValidator constructor.
         * Checks the locally stored encrypted license file without contacting the server.
         * Works for all license types: perpetual, subscription and server-side trial.
         * @return License status
         */
        LicenseStatus validateOffline() noexcept;

        /*!
        * Validate a local (client-only) trial license.
        * This method checks the trial due date stored locally on the device.
        * It does NOT contact the KEYZY server.
        *
        * For server-side trial licenses (registered via LicenseDepositHandler::registerTrial
        * or distributed through your own channel), use validateOnline(), validateOffline()
        * or activateSemiOnline() instead, as they follow the same flow as perpetual
        * and subscription licenses.
        *
        * @return LicenseStatus::VALID, LicenseStatus::EXPIRED or LicenseStatus::INVALID
        */
        LicenseStatus validateTrialLicense() noexcept;

        /*!
        * Get days to expire a local (client-only) trial license.
        * Not applicable for server-side trial licenses.
        * @return days to expire trial license or 0 if license has been expired
        */
        unsigned long long getDaysToExpireTrial();

        /*!
        * Get host id hash
        * @return string with host id hash
        */
        std::string getHostIdHash();
        
        /*!
         * Get host id hash legacy
         * @return string with host id hash used before 0.0.13 version
         */
        std::string getHostIdHashLegacy();
        
        /*!
         * Get Licensee Name string
         * @return string with licensee's name
         */
        std::string getLicenseeName();

        /*!
         * Get Licensee Email string
         * @return string with licensee's email address
         */
        std::string getLicenseeEmail();
        
        /*!
         * Get version string
         * @return string with version string like "full version" or "lite version"
         */
        std::string getVersion();
        
        /*!
         * Get sku string
         * @return string with sku
         */
        std::string getSku();
        
        /*!
         * Get license type string
         * @return string with license type
         */
        std::string getLicenseType();
        
        /*!
         * Get license type enum
         * @return LicenseType enum
         */
        LicenseType getLicenseTypeEnum();
        
        /*!
         * Get start time in Unix Timestamp
         * Start time is eligble for only Subscription and Trial licenses
         * it returns 315522000 default value if the license type is Perpetual
         * @return int64_t with start time
         */
        std::int64_t getStartTime();
        
        /*!
         * Get end time in Unix Timestamp
         * End time represents end time for Subscription and Trial licenses
         * If the license type is Perpetual, it represents Offline License Life
         * If Offline License Life is set to 0 on KEYZY dashboard, it returns 315522000 as default value
         * If Offline License Life is set to different than 0, it returns end time of the license
         * @return int64_t with end time
         */
        std::int64_t getEndTime();
        
        /*!
         * Get how many days left in Unix Timestamp
         * Days left represents how many days left to valid for Subscription and Trial licenses
         * If the license type is Perpetual, it represents Offline License Life
         * If Offline License Life is set to different than 0, it returns end time of the license
         * @return int64_t with days left
         *
         * Don't use this function with Perpetual licenses
         *
         */
        std::uint64_t getDaysLeft();

        /*!
         * Get total days in Unix Timestamp
         * Days total represents total days for Subscription and Trial licenses
         * If the license type is Perpetual, the value is garbage
         * @return int64_t with total days
         *
         * Don't use this function with Perpetual licenses
         *
         */
        std::uint64_t getDaysTotal();
        
        /*!
         * Get info string
         * info represents a string which is a custom text.
         * The software provider can customize each license with this info text.
         * @return string info
         */
        std::string getInfo();

    private:
        std::shared_ptr<KeyzyLicenseProvider> _licenseProvider;
        std::unique_ptr<vk::AuthSys2> _AuthSys;
        std::string _licenseeName;
        std::string _licenseeEmail;
        std::string _versionCode;
        std::string _sku;
        std::string _licenseType;
        std::int64_t _startTime;
        std::int64_t _endTime; //*!< If the license type is perpetual, it represents offline_license_life. If Offline License Life is set to 0 on KEYZY dashboard, it returns 315522000 as default value */
        std::string _info;
    };
} // Keyzy

#endif // KEYZY_LICENSE_VALIDATOR_H
