package inn.ocsf.bee.freigeld.core.model.data;

import com.querydsl.core.annotations.QueryEntity;
import inn.ocsf.bee.freigeld.core.model.*;
import org.bson.types.ObjectId;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.*;

@Document("person")
public class PersonData {

    @Id
    private ObjectId id;

    @Version
    private Long version;

    private Person person;

    private Map<String, PersonIdentity> identities = new HashMap<>();

    private List<String> identitySet = new ArrayList<>();

    private PersonType personType;

    public ObjectId getId() {
        return id;
    }

    public void setId(ObjectId id) {
        this.id = id;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Map<String, PersonIdentity> getIdentities() {
        return identities;
    }

    public void setIdentities(Map<String, PersonIdentity> identities) {
        this.identities = identities;
    }

    public List<String> getIdentitySet() {
        return identitySet;
    }

    public void setIdentitySet(List<String> identitySet) {
        this.identitySet = identitySet;
    }

    public PersonType getPersonType() {
        return personType;
    }

    public void setPersonType(PersonType personType) {
        this.personType = personType;
    }

    @QueryEntity
    public static class NaturalPersonImpl implements NaturalPerson {

        private String fullName;
        private UUID id;

        public NaturalPersonImpl() {
        }

        public NaturalPersonImpl(String fullName) {
            this.fullName = fullName;
            this.id = UUID.randomUUID();
        }

        @Override
        public UUID getId() {
            return id;
        }

        public void setId(UUID id) {
            this.id = id;
        }

        @Override
        public String getFullName() {
            return fullName;
        }

        public void setFullName(String fullName) {
            this.fullName = fullName;
        }
    }

    @QueryEntity
    public static class PrivatePersonImpl implements PrivatePerson {

        private UUID id;

        private UUID ownerId;

        public PrivatePersonImpl() {
        }

        public PrivatePersonImpl(@NotNull UUID ownerId) {
            this.ownerId = ownerId;
            this.id = UUID.randomUUID();
        }

        @Override
        public UUID getId() {
            return id;
        }

        public void setId(UUID id) {
            this.id = id;
        }

        @NotNull
        @Override
        public UUID getOwnerId() {
            return ownerId;
        }

        public void setOwnerId(UUID ownerId) {
            this.ownerId = ownerId;
        }
    }

    @QueryEntity
    public static class BankPrivate implements PrivatePerson {

        private UUID id;

        public BankPrivate() {
        }

        public BankPrivate(UUID id) {
            this.id = id;
        }

        @Override
        public UUID getId() {
            return id;
        }

        @NotNull
        @Override
        public UUID getOwnerId() {
            return UUID.randomUUID();
        }
    }
}
