package no.valg.valgnatt.database.hibernate;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Immutable;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
@Immutable
@NoArgsConstructor //Hibernate-krav
@AllArgsConstructor //Builder-krav
@Builder
public class BydelId implements java.io.Serializable, Comparable<BydelId> {

    @Getter
    @Column(name = "KOMMNR", nullable = false, length = 4)
    private String kommnr;

    @Getter
    @Column(name = "BYDELNR", nullable = false)
    private Integer bydelnr;

    public String id() {
        return kommnr + "-" + bydelnr;
    }

    @Override
    public boolean equals(Object other) {
        return other != null && other.getClass() == this.getClass() && id().equals(((BydelId) other).id());
    }

    @Override
    public int hashCode() {
        return id().hashCode();
    }

    @Override
    public int compareTo(BydelId o) {
        return toString().compareTo(o.toString());
    }

    public String toString() {
        return id();
    }

}
