package cn.palmte.work.model.process;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import javax.persistence.Convert;

import cn.palmte.work.model.enums.Enumerable;
import cn.palmte.work.model.enums.SealType;

/**
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
 * @since 2.0 2022/12/14 16:35
 */
@Convert(converter = SealTypeArrayConverter.class)
public class SealTypeArray implements Serializable {
  public static final SealTypeArray EMPTY = new SealTypeArray();

  private final List<SealType> list = new ArrayList<>();

  public SealTypeArray() { }

  public SealTypeArray(SealType... list) {
    Collections.addAll(this.list, list);
  }

  public List<SealType> getList() {
    return list;
  }

  public void setList(List<SealType> list) {
    this.list.clear();
    this.list.addAll(list);
  }

  @Override
  public String toString() {
    return list.stream()
            .map(SealType::getDescription)
            .collect(Collectors.joining(","));
  }

  //

  public static SealTypeArray of(SealType... sealTypes) {
    return new SealTypeArray(sealTypes);
  }

  public static SealTypeArray of(String... sealTypes) {
    return of(Arrays.stream(sealTypes)
            .map(type -> Enumerable.of(SealType.class, type))
            .toArray(SealType[]::new));
  }

  public static SealTypeArray of(Collection<SealType> sealTypes) {
    SealTypeArray sealTypeArray = new SealTypeArray();
    sealTypeArray.list.addAll(sealTypes);
    return sealTypeArray;
  }

}
