package no.valg.valgnatt.database.hibernate;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;

@Entity
@Table(name = "mandatberegning")
@NoArgsConstructor //Hibernate-krav
@AllArgsConstructor //Builder-krav
@Builder
public class Mandatberegning implements java.io.Serializable {

    @Getter
    @Setter
    @EmbeddedId
    private MandaterId id;

    @Getter
    @Column(name = "stemmer")
    private Integer stemmer;

    @Getter
    @Column(name = "antall")
    private Integer antall;

    @Column(name = "antall_stdm_i_fy")
    private Integer antallSTDMiFY;

    @Column(name = "antall_utj")
    private Integer antallUtj;

    @Setter
    @Column(name = "restkvotient_utj")
    private BigDecimal restkvotientUtj; // skrives i dette objektet - leses ut via SQL

    @Setter
    @Column(name = "mandatrang_utj")
    private Integer mandatrangUtj; // skrives i dette objektet - leses ut via SQL
    
    @Setter
    @Column(name = "siste_kvotient")
    private BigDecimal sisteKvotient;
    
    @Setter
    @Column(name = "siste_rang")
    private Integer sisteRang;
    
    @Setter
    @Column(name = "neste_kvotient")
    private BigDecimal nesteKvotient;
    
    @Setter
    @Column(name = "neste_rang")
    private Integer nesteRang;

    public void setStemmer(Integer stemmer) {
        if (stemmer == null) {
            this.stemmer = 0;
        } else {
            this.stemmer = stemmer;
        }
    }

    public void setAntall(Integer antall) {
        if (antall == null) {
            this.antall = 0;
        } else {
            this.antall = antall;
        }
    }

    public void setAntallSTDMiFY(Integer antallSTDMiFY) {
        if (antallSTDMiFY == null) {
            this.antallSTDMiFY = 0;
        } else {
            this.antallSTDMiFY = antallSTDMiFY;
        }
    }
    
    public void setAntallUtj(Integer antallUtj) {
        if (antallUtj == null) {
            this.antallUtj = 0;
        } else {
            this.antallUtj = antallUtj;
        }
    }
}
