package org.texttechnologylab.project.gruppe_05_1.database.domainimpl.mdb;

import org.bson.Document;
import org.texttechnologylab.project.gruppe_05_1.database.MongoDBHandler;
import org.texttechnologylab.project.gruppe_05_1.database.MongoOperations;
import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Membership;
import org.texttechnologylab.project.gruppe_05_1.domain.speaker.Speaker;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Speaker_Mongo_Impl extends Speaker implements MongoOperations<Speaker> {
    @Override
    public Document createEntity(Speaker entity) {

        List<Membership> memberships= entity.getMemberships();
        List<Document> membershipDocs = factory.createMemberships(memberships);

        Map<String, Object> fields = new HashMap<>();
        fields.put("_id",                  entity.getId());
        fields.put("name",                 entity.getName());
        fields.put("firstName",            entity.getFirstName());
        fields.put("title",                entity.getTitle());
        fields.put("geburtsdatum",         entity.getGeburtsdatum());
        fields.put("geburtsort",           entity.getGeburtsort());
        fields.put("sterbedatum",          entity.getSterbedatum());
        fields.put("geschlecht",           entity.getGeschlecht());
        fields.put("beruf",                entity.getBeruf());
        fields.put("akademischertitel",    entity.getAkademischertitel());
        fields.put("familienstand",        entity.getFamilienstand());
        fields.put("religion",             entity.getReligion());
        fields.put("vita",                 entity.getVita());
        fields.put("party",                entity.getParty());
        fields.put("memberships",          membershipDocs);

        return MongoDBHandler.createDocument(false, fields);
    }

    @Override
    public List<Document> createList(List<Speaker> list) {
        List<Document> result = new ArrayList<>();
        for (Speaker speaker : list) {
            result.add(createEntity(speaker));
        }
        return result;
    }
}
