/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-02 14:19:36
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-06-15 10:55:46
 */
#ifndef __SECTORPOWER_HPP_
#define __SECTORPOWER_HPP_

#include <iostream>
#include "ins_base.hpp"
#include <mutex>
#include <thread>
#include <condition_variable>
#include <queue>
#include <vector>
#include "Util/logger.h"
#include "Util/NoticeCenter.h"
#include "TaskCenter.hpp"

using namespace std;
using namespace toolkit;

namespace ins
{
    /**
     * @description: sectorPower 权力部门
     */    
    class Sectorpower:public Module
    {
    private:
        Sectorpower();
        
    public:
        using Ptr = std::shared_ptr<Sectorpower>;

        ~Sectorpower(){this->Destroy();}

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

        /**
         * @description: 初始化
         * @param {*}
         * @return {*}
         */        
        int8_t Init() override;

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

        /**
         * @description: 是否正常
         * @param {*}
         * @return {*}
         */        
        bool isNormally() override{
            return true;
        }

        /**
         * @description: 检查任务
         * @param {*}
         * @return {*}
         */        
        bool reviewTask(ins::InsTask::Ptr& task);

        /**
         * @description: 获取工作流任务
         * @param {*}
         * @return {*}
         */        
        InsTask::Ptr getWorkflowTask(InsPacket::Ptr pack);

        /**
         * @description: 业务入队
         * @param {*}
         * @return {*}
         */        
        int8_t enqueue(InsPacket::Ptr packet);

        /**
         * @description: 使能
         * @return {*}
         */        
        bool getEnable(){
            return Enable;
        }
        
        /**
         * @description: 设置使能
         * @param {bool} result
         * @return {*}
         */        
        bool setEnable(bool result){
            Enable = result;
            return true;
        }
        
    protected:
        mutex m_mutex;
        condition_variable condition;
        bool stop = false;
        vector<thread> workers;
        queue<InsPacket::Ptr> Transactions;
        bool Enable = false;
    };
} // namespace name






#endif