package org.texttechnologylab.project.gruppe_05_1.domain.html;

import org.bson.Document;
import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

public class HtmlSpeech {
    String                  speechKey;
    String                  speakerName;
    String                  fraction;
    List<SpeechContent> content = new ArrayList<>();

    public HtmlSpeech() {
    }

    public HtmlSpeech(Document doc) {
        setSpeechKey(doc.getString("speechKey"));
        setSpeakerName(doc.getString("speakerName"));
        setFraction(doc.getString("fraction"));

        List<Document> contentDocList = doc.get("speechContents", MongoDBHandler.DOC_LIST_CLASS);
        if (contentDocList == null) {
            setContent(new ArrayList<>());
        } else {
            for (Document contentDoc : contentDocList) {
                addContent(new SpeechContent(contentDoc));
            }
        }
    }

    public String getSpeechKey() {
        return speechKey;
    }

    public void setSpeechKey(String speechKey) {
        this.speechKey = speechKey;
    }

    public String getSpeakerName() {
        return speakerName;
    }

    public void setSpeakerName(String speakerName) {
        this.speakerName = speakerName;
    }

    public String getFraction() {
        return fraction;
    }

    public void setFraction(String fraction) {
        this.fraction = fraction;
    }

    public List<SpeechContent> getContent() {
        return content;
    }

    public void setContent(List<SpeechContent> content) {
        this.content = content;
    }

    public void addContent(SpeechContent contentLine) {
        content.add(contentLine);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof HtmlSpeech that)) return false;
        return Objects.equals(speechKey, that.speechKey) && Objects.equals(speakerName, that.speakerName) && Objects.equals(fraction, that.fraction) && Objects.equals(content, that.content);
    }

    @Override
    public int hashCode() {
        return Objects.hash(speechKey, speakerName, fraction, content);
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", HtmlSpeech.class.getSimpleName() + "[", "]")
                .add("speechKey='" + speechKey + "'")
                .add("speakerName='" + speakerName + "'")
                .add("fraction='" + fraction + "'")
                .add("content=" + content)
                .toString();
    }
}
