/*
 * Copyright © 2018 Cask Data, Inc.
 *
 * Licensed 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 io.cdap.cdap.api.lineage.field;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Represent the transform operation from collection of input fields to collection of output
 * fields.
 */
public class TransformOperation extends Operation {

  private final List<InputField> inputs;
  private final List<String> outputs;

  /**
   * Create the instance of a transform operation.
   *
   * @param name the name of the operation
   * @param description the description of the operation
   * @param inputs the list of input fields for operation
   * @param outputs the array of output fields generated by operation
   */
  public TransformOperation(String name, String description, List<InputField> inputs,
      String... outputs) {
    this(name, description, inputs, Arrays.asList(outputs));
  }

  /**
   * Create the instance of a transform operation.
   *
   * @param name the name of the operation
   * @param description the description of the operation
   * @param inputs the list of input fields for operation
   * @param outputs the list of output fields generated by operation
   */
  public TransformOperation(String name, String description, List<InputField> inputs,
      List<String> outputs) {
    super(name, OperationType.TRANSFORM, description);
    this.inputs = Collections.unmodifiableList(new ArrayList<>(inputs));
    this.outputs = Collections.unmodifiableList(new ArrayList<>(outputs));
  }

  /**
   * @return the list of input fields for this transform operation
   */
  public List<InputField> getInputs() {
    return inputs;
  }

  /**
   * @return the list of output fields generated by this transform operation
   */
  public List<String> getOutputs() {
    return outputs;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }

    if (!super.equals(o)) {
      return false;
    }
    TransformOperation that = (TransformOperation) o;
    return Objects.equals(inputs, that.inputs)
        && Objects.equals(outputs, that.outputs);
  }

  @Override
  public int hashCode() {
    return Objects.hash(super.hashCode(), inputs, outputs);
  }
}
