#ifndef KEYZY_LICENSE_MANAGER_H
#define KEYZY_LICENSE_MANAGER_H

/**
 * @file KeyzyLicenseManager.h
 * @brief License management: download/store license files, serial numbers, trials, and upgrades.
 */

#include "KeyzyTypes.h"
#include <memory>

namespace Keyzy
{
    class KeyzyLicenseProvider;
    
    /*!
    * @brief Low-level license management — download/store license files, serial numbers, trials, and upgrades.
    */
    class KeyzyLicenseManager
    {
    public:
        /*!
        * Create an instance of KeyzyLicenseManager that will manipulate licenses for a product defined in ProductData structure
        * @param productData Structure that describes a product for which going to set/delete licenses
        * @param licenseProvider is for not to create multiple object to prevent when update the license, update the provider
        */
        KeyzyLicenseManager(std::shared_ptr<KeyzyLicenseProvider> licenseProvider);
        ~KeyzyLicenseManager();

        /*!
        * Write serial number to a client machine.
        * This serial should be used by KeyzyLicenseValidator to validate if serial number is valid.
        * @param serial_number Serial number
        * @return true if serial has been set successfully, otherwise false
        */
        bool setSerialNumber(const std::string& serial_number);
       
        /*!
        * Write license file to a client machine.
        * This license file should be used by KeyzyLicenseValidator to validate if license file is valid.
        * @param license_file_path Absolute path to license file
        * @return true if license file has been set successfully, otherwise false
        */
        bool setLicenseFile(const std::string& license_file_path);

        /*!
         * Download license file from Keyzy server and write license file to a client machine.
         * This license file should be used by KeyzyLicenseValidator to validate if license file is valid.
         * @return License status.
         */
        LicenseStatus downloadLicenseFile() noexcept;
        
        /*!
         * Download license file from Keyzy server and write license file to a client machine.
         * This license file should be used by KeyzyLicenseValidator to validate if license file is valid.
         * @param serial_number Serial number
         * @return License status
         */
        LicenseStatus downloadLicenseFile(const std::string& serial_number) noexcept;
        
        /*!
         * Upgrade a license
         * @param source_serial Source serial number
         * @param target_serial Target serial number to upgrade to
         * @return License status
         */
        LicenseStatus upgradeLicense(const std::string& source_serial,
                                     const std::string& target_serial) noexcept;

        /*!
        * Write trial license to a client machine.
        * This trial license should be used by KeyzyLicenseValidator to validate if license file is valid.
        * @param dueData Due date of trial license
        * @return true if trial license has been set successfully, otherwise false
        */
        bool setTrialLicense(std::tm dueDate); //!< Set trial license 

        /*!
        * Delete serial number from a client machine
        * @return true if serial number has been deleted successfully, otherwise false
        */
        bool deleteSerialNumber();

        /*!
        * Delete license file from a client machine
        * @return true if license file has been deleted successfully, otherwise false
        */
        bool deleteLicenseFile();

        /*!
        * Delete trial license from a client machine
        * @return true if trial license has been deleted successfully, otherwise false
        */
        bool deleteTrialLicense();

    private:
        std::shared_ptr<KeyzyLicenseProvider> _licenseProvider;
    };
} // Keyzy

#endif // KEYZY_LICENSE_MANAGER_H
