/*
 * @Description: 
 * @Version: 1.0
 * @Autor: lishengyin
 * @Date: 2022-04-06 11:40:22
 * @LastEditors: lishengyin
 * @LastEditTime: 2022-04-27 16:23:04
 */
#include "ins_Packet.hpp"
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>

namespace ins
{
    
    /**
     * @description: 创造实例
     * @param {InsPacketTypes} sourceType
     * @param {InsPacketTypes} bournType
     * @param {InsUniversalData} data
     * @param {PackTaskPtr} packtask
     * @return {*}
     */    
    std::shared_ptr<InsPacket> InsPacket::CreateNew(InsPacketTypes sourceType, InsPacketTypes bournType, \
        InsUniversalData::Ptr data, InsPacket::PackTaskPtr packtask){
        return std::shared_ptr<InsPacket>(new InsPacket(sourceType, bournType, data, packtask));
    }

    /**
     * @description: 创建 PackTaskPtr
     * @param {function<void(InsPacket::Ptr)>} t
     * @return {*}
     */    
    InsPacket::PackTaskPtr InsPacket::MakePackTaskPtr(std::function<void(InsPacket::Ptr)> t){
         // todo审查数据格式是否合理
        return std::make_shared<std::function<void(InsPacket::Ptr)>>(t);
    }

    /**
     * @description: 判断是否有任务
     * @param {*}
     * @return {*}
     */    
    bool InsPacket::IsInsPackTask(){
        return this->insPackTask_ == nullptr ? false : true;
    }

    /**
     * @description: 获取PackTaskPtr
     * @param {*}
     * @return {*}
     */    
    InsPacket::PackTaskPtr InsPacket::getInsPackTask(){
        return this->insPackTask_;
    }

    /**
     * @description: 获取原始数据
     * @param {*}
     * @return {*}
     */    
    InsUniversalData::Ptr InsPacket::getData(){
        return this->data_;
    }

    /**
     * @description: 获取最终数据
     * @param {*}
     * @return {*}
     */    
    InsUniversalData::Ptr InsPacket::getToData(){
        return this->toData_;
    }

    /**
     * @description: 设置sql结果
     * @param {vector<vector<std::string>>} ret
     * @return {*}
     */    
    bool InsPacket::setSqlResult(vector<vector<std::string>> ret){
        this->result_ = ret;
        return true;
    }

    /**
     * @description: 获取到sql的结果
     * @param {*}
     * @return {*}
     */    
    vector<vector<std::string>> InsPacket::getSqlResult(){
        return result_;
    }

    /**
     * @description: 设置最终数据 
     * @param {*}
     * @return {*}
     */    
    bool InsPacket::setToData(InsUniversalData::Ptr Data){
        // todo审查数据格式是否合理
        this->toData_ = Data;
        return true;
    }
} // namespace ins

