/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.gravitino.dto.job;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.apache.gravitino.job.JobTemplateChange;

/** DTO for updating a Spark Job Template. */
@Getter
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(setterPrefix = "with")
@ToString(callSuper = true)
public class SparkTemplateUpdateDTO extends TemplateUpdateDTO {

  @Nullable
  @JsonProperty("newClassName")
  private String newClassName;

  @Nullable
  @JsonProperty("newJars")
  private List<String> newJars;

  @Nullable
  @JsonProperty("newFiles")
  private List<String> newFiles;

  @Nullable
  @JsonProperty("newArchives")
  private List<String> newArchives;

  @Nullable
  @JsonProperty("newConfigs")
  private Map<String, String> newConfigs;

  /**
   * The default constructor for Jackson. This constructor is required for deserialization of the
   * DTO.
   */
  private SparkTemplateUpdateDTO() {
    // Default constructor for Jackson
    super();
  }

  @Override
  public JobTemplateChange.TemplateUpdate toTemplateUpdate() {
    return JobTemplateChange.SparkTemplateUpdate.builder()
        .withNewExecutable(getNewExecutable())
        .withNewArguments(getNewArguments())
        .withNewEnvironments(getNewEnvironments())
        .withNewCustomFields(getNewCustomFields())
        .withNewClassName(newClassName)
        .withNewJars(newJars)
        .withNewFiles(newFiles)
        .withNewArchives(newArchives)
        .withNewConfigs(newConfigs)
        .build();
  }
}
