// ship.hpp - Clase para la nave del player
// © 1999 Visente i Sergi (versión Pascal)
// © 2025 Port a C++20 con SDL3

#pragma once
#include <SDL3/SDL.h>

#include <cstdint>

#include "core/defaults.hpp"
#include "core/entities/entity.hpp"
#include "core/types.hpp"

class Ship : public Entities::Entity {
    public:
        Ship()
            : Entity(nullptr) {}
        Ship(Rendering::Renderer* renderer, const char* shape_file = "ship.shp");

        void init() override { init(nullptr, false); }
        void init(const Vec2* spawn_point, bool activar_invulnerabilitat = false);
        void processInput(float delta_time, uint8_t player_id);
        void update(float delta_time) override;
        void postUpdate(float delta_time) override;
        void draw() const override;

        // Override: Interfaz de Entity
        [[nodiscard]] auto isActive() const -> bool override { return !is_hit_; }

        // Override: Interfaz de colisión
        [[nodiscard]] auto getCollisionRadius() const -> float override {
            return Defaults::Entities::SHIP_RADIUS;
        }
        [[nodiscard]] auto isCollidable() const -> bool override {
            return !is_hit_ && invulnerable_timer_ <= 0.0F;
        }

        // Getters (API pública sin cambios)
        [[nodiscard]] auto isAlive() const -> bool { return !is_hit_; }
        [[nodiscard]] auto isHit() const -> bool { return is_hit_; }
        [[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_timer_ > 0.0F; }
        // Velocidad como vector cartesiano (ahora viene directa del body_).
        [[nodiscard]] auto getVelocityVector() const -> Vec2 { return body_.velocity; }
        // Velocidad escalar (utilidad para draw y debugging).
        [[nodiscard]] auto getSpeed() const -> float { return body_.velocity.length(); }

        // Setters
        void setCenter(const Vec2& nou_centre) {
            center_ = nou_centre;
            body_.position = nou_centre;
        }

        // Colisiones
        void markHit() {
            is_hit_ = true;
            body_.velocity = Vec2{};  // Detener al morir
        }

    private:
        // Miembros específicos de Ship (heredados: renderer_, shape_, center_, angle_, brightness_, body_)
        bool is_hit_;
        float invulnerable_timer_;  // 0.0f = vulnerable, >0.0f = invulnerable
};
