package com.example.hotel.models;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;
import org.springframework.data.jpa.datatables.mapping.DataTablesOutput;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonView;

import lombok.Data;

@Entity
@Data
@Table(name = "hotel_accomodations")
public class Accomodation {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@JsonView(DataTablesOutput.View.class)
	private long id;

	@Column(name = "PLACES")
	@JsonView(DataTablesOutput.View.class)
	private Integer places = 0;

	@Temporal(TemporalType.DATE)
	@Column(name = "DATE_FROM")
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
	@JsonView(DataTablesOutput.View.class)
	private LocalDate dateFrom;

	@Temporal(TemporalType.DATE)
	@Column(name = "DATE_TO")
	@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
	@JsonView(DataTablesOutput.View.class)
	private LocalDate dateTo;

	@ManyToOne
	@JoinColumn(name = "RESIDENCE")
	@JsonView(DataTablesOutput.View.class)
	private Residence residence;

	@ManyToOne
	@JoinColumn(name = "ALLOCATION_ENTITY")
	@JsonView(DataTablesOutput.View.class)
	private AllocationEntity allocationEntity;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "accomodation")
	private List<CleaningSchedule> cleaningSchedules = new ArrayList<>();

}
