package eu.dnetlib.goldoa.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.google.gwt.user.client.rpc.IsSerializable;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name="Publisher")
public class Publisher implements IsSerializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(columnDefinition = "text")
	private String id;
	@Column(columnDefinition = "float default 0")
	private float apc;
	@Column(columnDefinition = "float default 0")
	private double discount;
	@Column(columnDefinition = "text")
	private String email;
	@Column(columnDefinition = "text")
	private String name;
	@Column(columnDefinition = "text")
	private String source;

	@Basic
	@Convert( converter=CurrencyConverter.class )
	private Currency apcCurrency;

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "bankAccount")
	private BankAccount bankAccount;

	@OneToMany(mappedBy = "pk.publisher", cascade=CascadeType.ALL,fetch = FetchType.LAZY)
	@JsonBackReference
	private List<PublisherDiscount> publisherDiscount = new ArrayList<>();

	@OneToMany( mappedBy = "publisher")
	@JsonBackReference(value = "contact")
	private List<User> contacts = new ArrayList<>();

	/*@ManyToMany(fetch = FetchType.LAZY, mappedBy = "publishers")
	@JsonBackReference(value = "budgets")
	private List<Budget> budgets = new ArrayList<>();*/

	public Publisher() {}

	public float getApc() {
		return this.apc;
	}

	public void setApc(float apc) {
		this.apc = apc;
	}

	public Currency getApcCurrency() {
		return this.apcCurrency;
	}

	public void setApcCurrency(Currency apcCurrency) {
		this.apcCurrency = apcCurrency;
	}



	public double getDiscount() {
		return this.discount;
	}

	public void setDiscount(double discount) {
		this.discount = discount;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getId() {
		return this.id;
	}

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

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSource() {
		return this.source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public BankAccount getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(BankAccount bankAccount) {
		this.bankAccount = bankAccount;
	}

	public List<PublisherDiscount> getPublisherDiscount() {
		return publisherDiscount;
	}

	public void setPublisherDiscount(List<PublisherDiscount> publisherDiscount) {
		this.publisherDiscount = publisherDiscount;
	}

	/*public List<Budget> getBudgets() {
		return budgets;
	}

	public void setBudgets(List<Budget> budgets) {
		this.budgets = budgets;
	}*/

	public List<User> getContacts() {
		return contacts;
	}

}