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

import org.bson.Document;

import java.util.Objects;
import java.util.StringJoiner;

public class SpeechContent {

    public enum SpeechContentType {SPEAKER, LINE, COMMENT}

    SpeechContentType   type;
    String              content;        // name und Fraktion für SPEAKER / content für LINE / comment für COMMENT

    public SpeechContent() {
    }

    public SpeechContent(Document doc) {
        String type = (String) doc.get("type");
        if (type.equalsIgnoreCase("speaker")) {
            setType(SpeechContentType.SPEAKER);
            setContent(doc.getString("speakerName") + " / " + doc.getString("fraction"));
        } else if (type.equalsIgnoreCase("line")) {
            setType(SpeechContentType.LINE);
            setContent(doc.getString("content"));
        } else if (type.equalsIgnoreCase("comment")) {
            setType(SpeechContentType.COMMENT);
            setContent(doc.getString("comment"));
        }
    }

    public SpeechContentType getType() {
        return type;
    }

    public void setType(SpeechContentType type) {
        this.type = type;
    }

    public String getContent() {
        return content;
    }

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


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

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

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

}
