package com.lanyuanxiaoyao.service.ai.knowledge.entity;

import java.util.List;
import java.util.Map;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.springframework.ai.document.Document;

/**
 * @author lanyuanxiaoyao
 * @version 20250523
 */
public class EmbeddingContext {
  private Long vectorSourceId;
  private Long groupId;
  private Config config;
  private String content;
  private String file;
  private String fileFormat;
  private List<Document> documents = Lists.mutable.empty();
  private Map<String, Object> metadata = Maps.mutable.empty();

  private EmbeddingContext(Builder builder) {
    setVectorSourceId(builder.vectorSourceId);
    setGroupId(builder.groupId);
    setConfig(builder.config);
    setContent(builder.content);
    setFile(builder.file);
    setFileFormat(builder.fileFormat);
  }

  public static Builder builder() {
    return new Builder();
  }

  public Long getGroupId() {
    return groupId;
  }

  public void setGroupId(Long groupId) {
    this.groupId = groupId;
  }

  public Long getVectorSourceId() {
    return vectorSourceId;
  }

  public void setVectorSourceId(Long vectorSourceId) {
    this.vectorSourceId = vectorSourceId;
  }

  public Config getConfig() {
    return config;
  }

  public void setConfig(Config config) {
    this.config = config;
  }

  public String getContent() {
    return content;
  }

  public void setContent(String content) {
    this.content = content;
  }

  public String getFile() {
    return file;
  }

  public void setFile(String file) {
    this.file = file;
  }

  public String getFileFormat() {
    return fileFormat;
  }

  public void setFileFormat(String fileFormat) {
    this.fileFormat = fileFormat;
  }

  public List<Document> getDocuments() {
    return documents;
  }

  public void setDocuments(List<Document> documents) {
    this.documents = documents;
  }

  public Map<String, Object> getMetadata() {
    return metadata;
  }

  public void setMetadata(Map<String, Object> metadata) {
    this.metadata = metadata;
  }

  @Override
  public String toString() {
    return "EmbeddingContext{" +
           "vectorSourceId=" + vectorSourceId +
           ", groupId=" + groupId +
           ", config=" + config +
           ", content='" + content + '\'' +
           ", file='" + file + '\'' +
           ", fileFormat='" + fileFormat + '\'' +
           ", documents=" + documents +
           ", metadata=" + metadata +
           '}';
  }

  public static final class Config {
    private SplitStrategy splitStrategy = SplitStrategy.NORMAL;

    private Config(Builder builder) {setSplitStrategy(builder.splitStrategy);}

    public static Builder builder() {
      return new Builder();
    }

    public SplitStrategy getSplitStrategy() {
      return splitStrategy;
    }

    public void setSplitStrategy(SplitStrategy splitStrategy) {
      this.splitStrategy = splitStrategy;
    }

    @Override
    public String toString() {
      return "Config{" +
             "splitStrategy=" + splitStrategy +
             '}';
    }

    public enum SplitStrategy {
      NORMAL, LLM, QA
    }

    public static final class Builder {
      private SplitStrategy splitStrategy;

      private Builder() {}

      public Builder splitStrategy(SplitStrategy val) {
        splitStrategy = val;
        return this;
      }

      public Config build() {
        return new Config(this);
      }
    }
  }

  public static final class Builder {
    private Long vectorSourceId;
    private Long groupId;
    private Config config;
    private String content;
    private String file;
    private String fileFormat;

    private Builder() {}

    public Builder vectorSourceId(Long val) {
      vectorSourceId = val;
      return this;
    }

    public Builder groupId(Long val) {
      groupId = val;
      return this;
    }

    public Builder config(Config val) {
      config = val;
      return this;
    }

    public Builder content(String val) {
      content = val;
      return this;
    }

    public Builder file(String val) {
      file = val;
      return this;
    }

    public Builder fileFormat(String val) {
      fileFormat = val;
      return this;
    }

    public EmbeddingContext build() {
      return new EmbeddingContext(this);
    }
  }
}
