#pragma once

#include <cstdint>
#include <cstdio>
#include "leveldb/slice.h"
#include "leveldb/write_batch.h"
#include "util/serialize_value.h"
#include "fielddb/field_db.h"
namespace fielddb {
using namespace leveldb;
/*根据写入的流程可以推断，需要存在metaDB中的数据其实都是带索引的数据,也就是FieldArray*/
// class MetaKV {
//     MetaKV(Slice &Key,FieldArray Fields):
//         Key(Key),Fields(Fields),tag(0),meta_seq(0) { }
//     inline int get_seq() { return meta_seq; }
//     inline void set_seq(int meta_seq) { this->meta_seq = meta_seq; }
//     inline void setPut() { tag = PUT; }
//     inline void setDelete() { tag = DELETE; }
//     Slice metaKey();
//     Slice metaValue();
// private:
//     enum {PUT = 0x0,DELETE = 0x1};
//     uint64_t meta_seq;
//     uint8_t tag;
//     Slice &Key;
//     FieldArray Fields;
// };

enum MetaType {
    //Index, //记录index状态的meta
    KV_Creating,  //记录含有index field的put的meta
    KV_Deleting,
};

//将一对(field_name,field_value)转换到metaDB中的KV表示
class MetaKV {
public:
    MetaKV(Slice field_name,Slice field_value = Slice()):
        name(field_name),value(field_value) { }
    void TransPut(std::string &MetaKey,std::string &MetaValue);
    void TransDelete(std::string &MetaKey);
private:
    Slice name;
    Slice value;
};

class MetaCleaner {
public:
    MetaCleaner() = default;
    void Collect(WriteBatch &MetaBatch);
    void CleanMetaBatch(DB *metaDB);
private:
    WriteBatch NeedClean;
};

}