#pragma once

#include "../../core/world/Chunk.hpp"
#include <memory>
#include "generator.hpp"

namespace world::server {

    /// Server size chunk
    class Chunk: public virtual world::Chunk {
    public:
        Chunk(): world::Chunk() { }
        Chunk(const chunk_pos &pos, const std::unique_ptr<generator::Abstract> &rnd);
        Chunk(std::istream& str, bool rle = RLE);
        virtual ~Chunk();

        /// Set voxel from index
        void set(chunk_voxel_idx idx, const Voxel& val);
        /// Set voxel from position
        void setAt(const chunk_voxel_pos& pos, const Voxel& val);

        /// Break voxel
        virtual std::optional<Item> replace(chunk_voxel_idx idx, const Voxel &val, float delay = 0);

        /// Is player modified
        inline bool isModified() const { return modified; }
        /// Write to file and return average (majorant material)
        /// Voxel swap bit indicate perfect majority
        Voxel write(std::ostream& str, bool rle = RLE) const;

    private:
        /// Modified by player
        bool modified = false;
    };
}
