#pragma once
#include "common.hpp"
#include "attr.hpp"


class Ent {
    private:
        const int dfd;
        int fd;
        bool fd_ro;
        Attr* attr;

        Ent(int, int, const char*, Attr*);
        static Ent* getInst(int, int, const char*, const struct stat*);
        void print(const char* prefix=NULL, const char* suffix=NULL) const;
        bool reopen(bool=false, bool=false);

    public:
        ~Ent();

        Ent(const char*);
        static Ent* getInst(int, const char*, bool, const struct stat* = NULL);
        static Ent* createInst(int, const char*, bool);

        bool read_from(Ent*, int bup=-1);
        bool apply(const Ent*);

        bool delInst(int bup=-1);

        typedef enum { TYPE_NONE=0, TYPE_REG, TYPE_DIR } type_t;
        const type_t type;
        const char* const name;

        static void print(const Ent* e, const char* prefix=NULL, const char* suffix=NULL);

        Attr::merge_t cmp(const Ent* o) const { return (type == o->type && type != TYPE_NONE)? attr->cmp(o->attr): Attr::FAIL; }
};