package org.pageseeder.ox.pageseeder.step;

import net.pageseeder.app.simple.pageseeder.service.PublishService;
import org.pageseeder.xmlwriter.XMLWritable;
import org.pageseeder.xmlwriter.XMLWriter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class GroupPublish implements XMLWritable {

  private String project;
  private String group;

  private String member;
  private String target;
  private PublishService.Type type;
  private PublishService.LogLevel logLevel;
  private HashMap<String, String> parameters;

  private String errorMessage;

  public GroupPublish(String project, String group, String target, String type, String logLevel) {
    this.project = project;
    this.group = group;
    this.target = target;
    this.type = PublishService.Type.valueOf(type);
    this.logLevel = PublishService.LogLevel.valueOf(logLevel);
  }

  public GroupPublish(String project, String group, String member, String target, String type, String logLevel, HashMap<String, String> parameters) {
    this.project = project;
    this.group = group;
    this.member = member;
    this.target = target;
    this.type = PublishService.Type.valueOf(type);
    this.logLevel = PublishService.LogLevel.valueOf(logLevel);
    this.parameters = parameters;
  }

  public GroupPublish(String project, String group, String target, String type, String logLevel, HashMap<String, String> parameters) {
    this.project = project;
    this.group = group;
    this.target = target;
    this.type = PublishService.Type.valueOf(type);
    this.logLevel = PublishService.LogLevel.valueOf(logLevel);
    this.parameters = parameters;
  }

  public String getProject() {
    return project;
  }

  public String getGroup() {
    return group;
  }

  public String getMember() {
    return member;
  }

  public String getTarget() {
    return target;
  }

  public PublishService.Type getType() {return type; }

  public PublishService.LogLevel getLogLevel() {
    return logLevel;
  }

  public HashMap<String, String> getParameters() { return parameters;
  }

  @Override
  public void toXML(XMLWriter xml) throws IOException {
    xml.openElement("action");
    xml.attribute("project", this.getProject());
    xml.attribute("group", this.getGroup());
    xml.attribute("target", this.getTarget());
    xml.attribute("type", this.getType().toString());
    xml.attribute("log-level", this.getLogLevel().toString());
    for (Map.Entry<String, String> entry : getParameters().entrySet()) {
      xml.attribute(entry.getKey(), entry.getValue());
    }
    xml.closeElement();
  }

//  public void addErrorMessages(XMLWriter writer) {
//    for (String message : status.getMessages()) {
//      if (StringUtils.isBlank(message)) {
//        writer.element("message", message);
//      }
//    }
//  }

}

@@ -587,304 +587,8 @@
 e;%0A%0A
-  public GroupPublish(String project, String group, String target, String type, String logLevel) %7B%0A    this.project = project;%0A    this.group = group;%0A    this.target = target;%0A    this.type = PublishService.Type.valueOf(type);%0A    this.logLevel = PublishService.LogLevel.valueOf(logLevel);%0A  %7D%0A%0A
   pu
@@ -877,32 +877,46 @@
 ype.valueOf(type
+.toUpperCase()
 );%0A    this.logL
@@ -966,374 +966,22 @@
 evel
-);%0A    this.parameters = parameters;%0A  %7D%0A%0A  public GroupPublish(String project, String group, String target, String type, String logLevel, HashMap%3CString, String%3E parameters) %7B%0A    this.project = project;%0A    this.group = group;%0A    this.target = target;%0A    this.type = PublishService.Type.valueOf(type);%0A    this.logLevel = PublishService.LogLevel.valueOf(logLevel
+.toUpperCase()
 );%0A 
@@ -1964,226 +1964,6 @@
  %7D%0A%0A
-//  public void addErrorMessages(XMLWriter writer) %7B%0A//    for (String message : status.getMessages()) %7B%0A//      if (StringUtils.isBlank(message)) %7B%0A//        writer.element(%22message%22, message);%0A//      %7D%0A//    %7D%0A//  %7D%0A%0A
 %7D%0A

Format enum values to uppercase