/*
 * @Description: ApiServer api服务器
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-01 15:44:09
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-04-15 11:19:25
 */
#ifndef __APISERVER_HPP_
#define __APISERVER_HPP_

#include <iostream>
#include "HttpServer.h"
#include "hssl.h"

#include "ins_base.hpp"

using namespace std;

namespace ins{

    class ApiServer:public Module
    {
    private:
        ApiServer(int port) : Module("ApiServer"), port_(port){
            Init();
        }

        /**
         * @description: 注册API
         * @param {*}
         * @return {*}
         */        
        int8_t RegisterApi();

    public:
        using Ptr = std::shared_ptr<ApiServer>;
        
        virtual ~ApiServer(){this->Destroy();}
        
        /**
         * @description: 初始化
         * @param {*}
         * @return {*}
         */        
        int8_t Init() override;

        /**
         * @description: 创建实例
         * @param {*}
         * @return {*}
         */        
        static std::shared_ptr<ApiServer> CreateNew(int port);

        /**
         * @description: 获取实例
         * @param {*}
         * @return {*}
         */        
        static std::shared_ptr<ApiServer> getPtr();

        /**
         * @description: 释放资源
         * @param {*}
         * @return {*}
         */        
        void Destroy() override;

        /**
         * @description: 运行
         * @param {*}
         * @return {*}
         */        
        int8_t Run();

        /**
         * @description: 是否正常
         * @param {*}
         * @return {*}
         */        
        bool isNormally() override{
            return true;
        }
        
    protected:
        int port_;
        http_server_t server_;
        std::shared_ptr<HttpService> m_HttpService = nullptr;
    };
};

// 任务管理器



#endif

