package marketing.heyday.hartmann.fotodocumentation.core.model;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.HashCodeBuilder;

import jakarta.persistence.*;

/**
 * 
 * 
 * <p>Copyright: Copyright (c) 2024</p>
 * <p>Company: heyday Marketing GmbH</p>
 * @author <a href="mailto:p.verboom@heyday.marketing">Patrick Verboom</a>
 * @version 1.0
 * 
 * created: 19 Jan 2026
 */

@Entity
@Table(name = "customer")
@NamedQuery(name =  Customer.FIND_ALL, query = "select c from Customer c order by c.name")
@NamedQuery(name =  Customer.FIND_BY_NUMBER, query = "select c from Customer c where c.customerNumber = :cutomerNumber")
public class Customer extends AbstractDateEntity {
	private static final long serialVersionUID = 1L;
	public static final String SEQUENCE = "customer_seq";
	public static final String FIND_ALL = "Customer.findAll";
	public static final String FIND_BY_NUMBER = "Customer.findByNumber";
	public static final String PARAM_NUMBER = "cutomerNumber";

	@Id
	@Column(name = "customer_id", length = 22)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SEQUENCE)
	@SequenceGenerator(name = SEQUENCE, sequenceName = SEQUENCE, allocationSize = 1)
	private Long customerId;

	@Column(name = "customer_number", unique = true, nullable = false)
	private String customerNumber;

	@Column(name = "name", nullable = false)
	private String name;

	@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
	private Set<Picture> pictures = new HashSet<>();

	public Long getCustomerId() {
		return customerId;
	}

	public void setCustomerId(Long customerId) {
		this.customerId = customerId;
	}

	public String getCustomerNumber() {
		return customerNumber;
	}

	public void setCustomerNumber(String customerNumber) {
		this.customerNumber = customerNumber;
	}

	public String getName() {
		return name;
	}

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

	public Set<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(Set<Picture> pictures) {
		this.pictures = pictures;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(customerNumber).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || this.getClass() != obj.getClass()) {
			return false;
		}
		return this.customerNumber.equals(((Customer) obj).getCustomerNumber());
	}

	public static class Builder {
		private Customer instance = new Customer();

		public Builder customerNumber(String customerNumber) {
			instance.setCustomerNumber(customerNumber);
			return this;
		}

		public Builder name(String name) {
			instance.setName(name);
			return this;
		}

		public Customer build() {
			return instance;
		}
	}
}
