package de.hhu.stups.plues.data.entities;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Type;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "log")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "log")
public class Log implements Serializable {

  private static final long serialVersionUID = 8715213161059401044L;

  @ManyToOne(fetch = FetchType.EAGER)
  @Id
  private Session session;

  @Id
  private String src;

  @Id
  private String target;

  @CreationTimestamp
  @Type(type = "org.hibernate.usertype.SqliteDateTimeType")
  @Column(name = "created_at")
  private Date createdAt;

  public Log() {
    // Default constructor is required by hibernate
  }

  public Session getSession() {
    return session;
  }

  public void setSession(final Session session) {
    this.session = session;
  }

  public String getSrc() {
    return src;
  }

  public void setSrc(final String src) {
    this.src = src;
  }

  public String getTarget() {
    return target;
  }

  public void setTarget(final String target) {
    this.target = target;
  }

  @Override
  public boolean equals(final Object other) {
    if (this == other) {
      return true;
    }
    if (other == null || getClass() != other.getClass()) {
      return false;
    }
    final Log log = (Log) other;
    return Objects.equals(session, log.session)
        && Objects.equals(src, log.src)
        && Objects.equals(target, log.target)
        && Objects.equals(createdAt, log.createdAt);
  }

  @Override
  public int hashCode() {
    return Objects.hash(session, src, target, createdAt);
  }

  public Date getCreatedAt() {
    return (Date) createdAt.clone();
  }

  public void setCreatedAt(final Date createdAt) {
    this.createdAt = (Date) createdAt.clone();
  }
}

@@ -819,40 +819,115 @@
  src
-;%0A%0A  @Id%0A  private String target
+Day;%0A%0A  @Id%0A  private String srcTime;%0A%0A  @Id%0A  private String targetDay;%0A%0A  @Id%0A  private String targetTime
 ;%0A%0A 
@@ -1300,16 +1300,19 @@
 g getSrc
+Day
 () %7B%0A   
@@ -1318,24 +1318,83 @@
   return src
+Day;%0A  %7D%0A%0A  public String getSrcTime() %7B%0A    return srcTime
 ;%0A  %7D%0A%0A  pub
@@ -1406,18 +1406,21 @@
 oid setS
+ou
 rc
+e
 (final S
@@ -1428,16 +1428,41 @@
 ring src
+Day, final String srcTime
 ) %7B%0A    
@@ -1473,14 +1473,48 @@
 .src
+Day
  = src
+Day;%0A    this.srcTime = srcTime
 ;%0A  
@@ -1541,16 +1541,19 @@
 etTarget
+Day
 () %7B%0A   
@@ -1562,24 +1562,89 @@
 eturn target
+Day;%0A  %7D%0A%0A  public String getTargetTime() %7B%0A    return targetTime
 ;%0A  %7D%0A%0A  pub
@@ -1681,16 +1681,44 @@
 g target
+Day, final String targetTime
 ) %7B%0A    
@@ -1728,16 +1728,19 @@
 s.target
+Day
  = targe
@@ -1740,16 +1740,53 @@
 = target
+Day;%0A    this.targetTime = targetTime
 ;%0A  %7D%0A%0A 
@@ -2088,118 +2088,382 @@
 als(
-src, log.src)%0A        && Objects.equals(target, log.target)%0A        && Objects.equals(createdAt, log.createdAt
+createdAt, log.createdAt)%0A        && equalsSource(log)%0A        && equalsTarget(log);%0A  %7D%0A%0A  private boolean equalsSource(final Log log) %7B%0A    return Objects.equals(srcDay, log.srcDay) && Objects.equals(srcTime, log.srcTime);%0A  %7D%0A%0A  private boolean equalsTarget(final Log log) %7B%0A    return Objects.equals(targetDay, log.targetDay) && Objects.equals(targetTime, log.targetTime
 );%0A 
@@ -2544,16 +2544,43 @@
  src
-, target
+Day, srcTime, targetDay, targetTime
 , cr

split id 'target' to 'targetDay' and 'targetTime', same for the source slot