# This is API for write scripts with SysPack
# Maybe unstable!
from libs.spk_v.tkmg import VTask
from libs.unirepo.unirepo import UniRepo


class SPK5_API:
    def __init__(self, syspack_instance):
        self.syspack_instance = syspack_instance
        self.log = syspack_instance.log
        self.osa = syspack_instance.osa
        self.runtime = None

    def get_logger(self):
        return self.log

    def get_osa(self):
        return self.osa

    def get_repoman(self) -> UniRepo:
        return self.syspack_instance.repository

    def add_task(self, task : VTask):
        return self.runtime.rtask_manager.queue.append(task)

    def run_tasks(self):
        return self.runtime.rtask_manager.run_tasks(self.syspack_instance)

    def pkg_search(self, query, strict=True):
        self.syspack_instance.apply_filters(query)

        return self.syspack_instance.repository.search(query, strict)
