package de.accso.flexinale.domain.model;

import de.accso.flexinale.shared_kernel.EqualsByContent;
import de.accso.flexinale.shared_kernel.Identifiable;
import de.accso.flexinale.shared_kernel.RawWrapper;
import de.accso.flexinale.shared_kernel.Versionable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class Besucher implements Identifiable, Versionable, EqualsByContent {
    public record Login(String raw) implements RawWrapper<String> {}
    public record EmailAdresse(String raw) implements RawWrapper<String> {}
    public record Name(String raw) implements RawWrapper<String> {}
    public record Vorname(String raw) implements RawWrapper<String> {}

    public final Id id;
    public final Version version;

    public final Login login;
    public final EmailAdresse emailAdresse;
    public final Name name;
    public final Vorname vorname;

    public Besucher(final Id id,
                    final Login login, final EmailAdresse emailAdresse, final Name name, final Vorname vorname) {
        this(id, Versionable.unknownVersion(), login, emailAdresse, name, vorname);
    }

    public Besucher(final Id id, final Version version,
                    final Login login, final EmailAdresse emailAdresse, final Name name, final Vorname vorname) {
        this.id = id;
        this.version = version;
        this.login = login;
        this.emailAdresse = emailAdresse;
        this.name = name;
        this.vorname = vorname;
    }

    @Override
    public Id id() {
        return id;
    }

    @Override
    public Version version() {
        return version;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }

    @Override
    public boolean equals(final Object o) {
        if (!equalsByContent(o)) return false;

        if (this == o) {return true;}
        if (o == null || getClass() != o.getClass()) {return false;}
        Besucher that = (Besucher) o;
        return new EqualsBuilder().append(version, that.version).isEquals();
    }

    @Override
    public boolean equalsByContent(final Object o) {
        if (this == o) {return true;}

        if (o == null || getClass() != o.getClass()) {return false;}

        Besucher that = (Besucher) o;

        return new EqualsBuilder()
                .append(id, that.id)
                .append(login, that.login)
                .append(emailAdresse, that.emailAdresse).append(name, that.name)
                .append(vorname, that.vorname).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(id).append(version)
                .append(login).append(emailAdresse).append(name).append(vorname).toHashCode();
    }
}
