#set ($attributes = $model.attributes)
#foreach ($key in $attributes.keySet())
  #if ($key.getName().equals("CUSTOM_RESOURCE_CONFIG"))
    #set ($config = $attributes.get($key))
    #set ($group = $config.group)
    #set ($version = $config.version)
    #set ($kind = $config.kind)
    #set ($modelPackage = $config.modelPackage)
  #end
#end

package ${model.packageName}.handler;

import java.util.function.Predicate;

import io.dekorate.deps.kubernetes.client.Config;
import io.dekorate.deps.kubernetes.client.ResourceHandler;
import io.dekorate.deps.kubernetes.client.Watch;
import io.dekorate.deps.kubernetes.client.Watcher;
import ${model.packageName}.${kind};
import ${model.packageName}.operation.${kind}OperationsImpl;

import io.dekorate.deps.okhttp3.OkHttpClient;

import ${model.fullyQualifiedName};
import ${model.fullyQualifiedName}Builder;

import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class ${kind}Handler implements ResourceHandler<${kind}, ${kind}Builder> {
  @Override
  public String getKind() {
    return ${kind}.class.getSimpleName();
  }

  @Override
  public ${kind} create(OkHttpClient client, Config config, String namespace, ${kind} item) {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).create();
  }

  @Override
  public ${kind} replace(OkHttpClient client, Config config, String namespace, ${kind} item) {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, true, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).replace(item);
  }

  @Override
  public ${kind} reload(OkHttpClient client, Config config, String namespace, ${kind} item) {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).fromServer().get();
  }

  @Override
  public ${kind}Builder edit(${kind} item) {
    return new ${kind}Builder(item);
  }

  @Override
  public Boolean delete(OkHttpClient client, Config config, String namespace, ${kind} item) {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).delete(item);
  }

  @Override
  public Watch watch(OkHttpClient client, Config config, String namespace, ${kind} item, Watcher<${kind}> watcher) {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).watch(watcher);
  }

  @Override
  public Watch watch(OkHttpClient client, Config config, String namespace, ${kind} item, String resourceVersion, Watcher<${kind}> watcher) {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).watch(resourceVersion, watcher);
  }

  @Override
  public ${kind} waitUntilReady(OkHttpClient client, Config config, String namespace, ${kind} item, long amount, TimeUnit timeUnit) throws InterruptedException {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).waitUntilReady(amount, timeUnit);
  }

  @Override
  public ${kind} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${kind} item, Predicate<${kind}> condition, long amount, TimeUnit timeUnit) throws InterruptedException {
    return new ${kind}OperationsImpl(client, config, "$apiGroup", "$apiVersion", namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).waitUntilCondition(condition, amount, timeUnit);
  }
}
