#include <Block/SpriteBlock/BasicBlock/GrindingBowl/GrindingBowl.hpp>
#include <Milestone/BrickByBrickMilestone/BrickByBrickMilestone.hpp>
#include <Utilities/Utilities.hpp>
#include <Entity/PhysicsEntity/CameraEntity/Player/Player.hpp>
#include <Controller/InventoryController/GrindingBowlController/GrindingBowlController.hpp>
#include <World/LocalWorld/LocalWorld.hpp>

GrindingBowl::GrindingBowl(std::string name) : BasicBlock(
    name,
    "Grinding bowl",
    60.0f,
    {"grindingBowlSide", "grindingBowlSide", "grindingBowlSide", "grindingBowlSide", "clay", "grindingBowlTop"},
    {0, 0, 0, 8, 8, 4}
)
{}

void GrindingBowl::onInteract(LocalWorld &world, Player &player, glm::ivec3 pos, Side side, const RGBABytes &collisionKey)
{
    player.achieve(BrickByBrickMilestone::ID, BrickByBrickMilestone::MakeGrindingBowl);
    player.connectController<GrindingBowlController>(
        "main:GrindingBowlController",
        world.getMachine(pos)
    );
}

void GrindingBowl::getHarvestedStacks(LocalWorld &world, glm::ivec3 pos, std::vector<ItemStack> &stacks)
{
    BasicBlock::getHarvestedStacks(world, pos, stacks);

    std::shared_ptr<IInventory> inv = std::dynamic_pointer_cast<IInventory>(world.getMachine(pos));
    if (inv != nullptr)
    {
        int i;
        for (i=0; i<inv->getNumSlots(); i++)
        {
            ItemStack stack = inv->getStackInSlot(i);
            if (!stack.isEmpty())
            {
                stacks.push_back(stack);
            }
        }
    }
}

bool GrindingBowl::canManuallyDig()
{
    return true;
}