from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake
from conans import tools  # type: ignore[misc, no-any-unimported]

class {{ config.project.name|capitalize|replace("-", "") }}Conan(ConanFile):  # type: ignore[misc, no-any-unimported]
    name = "{{ config.project.name }}"
    version = "{{ config.project.version }}"
    settings = "os", "compiler", "build_type", "arch"
    description = "{{ config.project.description }}"
    url = "{{ config.project.homepage_url }}"
    generators = "CMakeDeps"
    exports_sources = "src/*", "CMakeLists.txt"

    def generate(self):
        tc = CMakeToolchain(self)
        tc.generate()

    def package(self) -> None:
        self.copy("*", src='build/Debug/bin/', dst='bin', keep_path=False)
        self.copy("*", src='build/Debug/lib/', dst='lib', keep_path=False)

    def package_info(self) -> None:
        self.cpp_info.libs = tools.collect_libs(self)

    def build(self) -> None:
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def source(self) -> None:
        {% if config.project.target.family == "stm32" %}
        git = tools.Git(folder="third-party/stm32-cmake")
        git.clone("https://github.com/ObKo/stm32-cmake.git", "master")
        {% else %}
        pass
        {% endif %}

    {% if config.dependencies.build or config.dependencies.tool %}
    def build_requirements(self) -> None:
        {% for dep in config.dependencies.build %}
        self.requires("{{ dep }}")
        {% endfor %}
        {% for tool_dep in config.dependencies.tool %}
        self.tool_requires("{{ tool_dep }}")
        {% endfor %}

    {% endif %}
    {% if config.dependencies.general %}
    def requirements(self) -> None:
        {% for dep in config.dependencies.general %}
        self.requires("{{ dep }}")
        {% endfor %}
    {% endif %}
