#include <kubecontrol/Container.hpp>


namespace kubecontrol
{
    Container::Container(const std::string &Owner, const std::string &Uuid, const std::string &Image, const PullPolicy &policy, const std::string &registry ):
    owner_(Utils::to_lower(Owner)),
    uuid_(Utils::to_lower(Uuid)),
    image_(Utils::to_lower(Image)),
    pullPolicy_(policy),
    registry_(registry)
    {

    }


    void Container::addEnv(const std::pair<std::string, std::string> &env)
    {
        this->envs_.emplace(env);
    }

    void Container::addEnv(const std::map<std::string, std::string> &envs)
    {

        this->envs_ = envs;
    }



    YAML::Node Container::toYAML()
    {
        YAML::Node container;

        container["name"] = uuid_+"-container";
        container["image"] = this->registry_ + "/"+image_;
        container["imagePullPolicy"] = toString(pullPolicy_);

        if (!envs_.empty())
        {
            int lauf = 0;
            for(auto [key,value] : envs_)
            {
                container["env"][lauf]["name"] = key;
                container["env"][lauf]["value"] = value;
                lauf++;
            }

        }
        return container;
    }




}
