//
// Created by spenc on 5/22/2025.
//

#pragma once

#include <yaml-cpp/yaml.h>

namespace OX
{
    class GameObject;

    class Component
    {
    public:
        virtual ~Component() = default;

        /// Called when this component is attached to a GameObject.
        virtual void OnAttach(GameObject *owner) { m_owner = owner; }

        /// Called just before this component is detached or destroyed.
        virtual void OnDetach() { m_owner = nullptr; }

        /// Returns the GameObject this component is attached to (or nullptr).
        [[nodiscard]] GameObject *GetOwner() const { return m_owner; }

        /// Serialize this component’s state into a YAML node.
        [[nodiscard]] virtual YAML::Node Serialize() const = 0;

        /// Restore this component’s state from a YAML node.
        virtual void Deserialize(const YAML::Node &node) = 0;

    protected:
        GameObject *m_owner = nullptr;
    };
};
