#include "corefactorysfml.h"

#include "rectanglesfml.h"
#include "musicsfml.h"
#include "textsfml.h"
#include "linesfml.h"
#include "spritesfml.h"

CoreFactorySFML::CoreFactorySFML(sf::RenderTarget * const render_target) :
    _render_target(render_target)
{
    auto gui_font = std::make_unique<sf::Font>();
    gui_font->loadFromFile("resources/SourceCodePro-Regular.ttf");
    _font_holder.load(kku::Font::Id::GUI, std::move(gui_font));

    auto menu_texture = std::make_unique<sf::Texture>();
    menu_texture->loadFromFile("resources/gui-texture.png");
    _texture_holder.load(kku::Texture::Id::GUI, std::move(menu_texture));
}

std::shared_ptr<kku::Music> CoreFactorySFML::getMusic() const
{
    return std::make_unique<MusicSFML>();
}

std::shared_ptr<kku::Text> CoreFactorySFML::getText(kku::Font::Id id) const
{
    return std::make_unique<TextSFML>(_render_target, _font_holder.get(id));
}

std::shared_ptr<kku::Rectangle> CoreFactorySFML::getRectangle() const
{
    return std::make_unique<RectangleSFML>(_render_target);
}

 std::shared_ptr<kku::Line> CoreFactorySFML::getLine() const
 {
     return std::make_unique<LineSFML>(_render_target);
 }

 std::shared_ptr<kku::Sprite> CoreFactorySFML::getSprite(kku::GUISprite::Id id) const
 {
    const auto texture = _texture_holder.get(kku::Texture::Id::GUI);
    switch (id)
    {
    default:
        return nullptr;
        break;

    case kku::GUISprite::Id::SFML_LOGO:
        return std::make_unique<SpriteSFML>(_render_target, _texture_holder.get(kku::Texture::Id::GUI),
                                            kku::Area<unsigned int>{0, 0, 252, 81});
        break;

    case kku::GUISprite::Id::CRYPTOPP_LOGO:
        return std::make_unique<SpriteSFML>(_render_target, _texture_holder.get(kku::Texture::Id::GUI),
                                            kku::Area<unsigned int>{252, 0, 135, 36});
        break;
    }
 }

kku::Vector2<std::size_t> CoreFactorySFML::getRenderSize() const
{
    const sf::Vector2u size = _render_target->getSize();
    return kku::makeVector(size.x, size.y);
}
