from common import get_env_variable_required
from src.interface.dotnet_project import DotnetProjectInterface


class DotnetLib(DotnetProjectInterface):
    def __init__(self):
        super().__init__()
        self.publish_type = "pack"

    def package(self):
        self._configure_nuget()
        self._publish()

        nexus_username = get_env_variable_required("NEXUS_USERNAME")
        nexus_password = get_env_variable_required("NEXUS_PASSWORD")
        nexus_nuget_api_key = get_env_variable_required("NEXUS_NUGET_API_KEY")
        repo_url = "https://nexus.senior.com.br/repository/nuget-hosted/"

        self._exec_dotnet_command(
            f"nuget add source {repo_url} --name nexus "
            f"--username {nexus_username} --password {nexus_password} --store-password-in-clear-text"
        )
        self._exec_dotnet_command(
            f"nuget push {self.ci_project_dir}/output/*.nupkg --api-key {nexus_nuget_api_key} --source {repo_url}"
        )
