package de.jottyfan.camporganizer.module.business.outlay.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.time.LocalDateTime;
import java.util.Locale;

import org.springframework.format.annotation.DateTimeFormat;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 *
 * @author jotty
 *
 */
public class OutlayBean implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer id;
	@NotBlank
	private String trader;
	@NotNull
	private Integer fkCamp;
	private String campname;
	private String provider;
	@NotNull
	private BigDecimal cash;
	@DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss")
	private LocalDateTime buydate;
	private String recipenumber;
	private String recipenote;
	private String ingredients;

	public OutlayBean withUser(String provider) {
		this.provider = provider;
		return this;
	}

	private static final String quoted(String s) {
		return s == null ? "" : String.format("\"%s\"", s.replace("\"", "'"));
	}

	private static final String cashed(BigDecimal money) {
		return money == null ? "" :  String.format("%s €", NumberFormat.getNumberInstance(Locale.GERMAN).format(money));
	}

	public String toCsvLine() {
		StringBuilder buf = new StringBuilder();
		buf.append(recipenumber).append(";");
		buf.append(quoted(trader)).append(";");
		buf.append(quoted(campname)).append(";");
		buf.append(quoted(provider)).append(";");
		buf.append(cashed(cash)).append(";");
		buf.append(quoted(ingredients)).append(";");
		buf.append(buydate).append("\n");
		return buf.toString();
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the trader
	 */
	public String getTrader() {
		return trader;
	}

	/**
	 * @param trader the trader to set
	 */
	public void setTrader(String trader) {
		this.trader = trader;
	}

	/**
	 * @return the campname
	 */
	public String getCampname() {
		return campname;
	}

	/**
	 * @param campname the campname to set
	 */
	public void setCampname(String campname) {
		this.campname = campname;
	}

	/**
	 * @return the cash
	 */
	public BigDecimal getCash() {
		return cash;
	}

	/**
	 * @param cash the cash to set
	 */
	public void setCash(BigDecimal cash) {
		this.cash = cash;
	}

	/**
	 * @return the buydate
	 */
	public LocalDateTime getBuydate() {
		return buydate;
	}

	/**
	 * @param buydate the buydate to set
	 */
	public void setBuydate(LocalDateTime buydate) {
		this.buydate = buydate;
	}

	/**
	 * @return the provider
	 */
	public String getProvider() {
		return provider;
	}

	/**
	 * @param provider the provider to set
	 */
	public void setProvider(String provider) {
		this.provider = provider;
	}

	/**
	 * @return the recipenumber
	 */
	public String getRecipenumber() {
		return recipenumber;
	}

	/**
	 * @param recipenumber the recipenumber to set
	 */
	public void setRecipenumber(String recipenumber) {
		this.recipenumber = recipenumber;
	}

	/**
	 * @return the recipenote
	 */
	public String getRecipenote() {
		return recipenote;
	}

	/**
	 * @param recipenote the recipenote to set
	 */
	public void setRecipenote(String recipenote) {
		this.recipenote = recipenote;
	}

	/**
	 * @return the ingredients
	 */
	public String getIngredients() {
		return ingredients;
	}

	/**
	 * @param ingredients the ingredients to set
	 */
	public void setIngredients(String ingredients) {
		this.ingredients = ingredients;
	}

	/**
	 * @return the fkCamp
	 */
	public Integer getFkCamp() {
		return fkCamp;
	}

	/**
	 * @param fkCamp the fkCamp to set
	 */
	public void setFkCamp(Integer fkCamp) {
		this.fkCamp = fkCamp;
	}
}
