package org.exoplatform.cs.entity;

import java.util.Calendar;


import javax.persistence.*;
import lombok.Data;
import org.exoplatform.commons.api.persistence.ExoEntity;
import org.exoplatform.cs.dto.LogType;

/**
 * Created by IntelliJ IDEA.
 * User: ali
 * Date: 04/01/17
 * Time: 18:39
 */
@Entity(name = "CSLogEntity")
@ExoEntity
@Table(name = "CS_ADDON_LOG")
@NamedQueries({ @NamedQuery(name = "logEntity.getLogsByTicket", query = "SELECT a FROM CSLogEntity a where a.topic.space.id = :spaceGroupID and a.topic = :topic")})
@Data
public class LogEntity {
  @Id
  @SequenceGenerator(name = "SEQ_CS_LOG_ID")
  @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CS_LOG_ID")
  @Column(name = "LOG_ID")
  private String            id;

  @Column(name = "TYPE")
  private LogType type;

  @Column(name = "USER")
  private String userID;

  @Column(name = "DATE")
  @Temporal(TemporalType.TIMESTAMP)
  private Calendar when;

  @Column(name = "ORIGINAL_VALUE")
  private String originalValue;

  @Column(name = "NEW_VALUE")
  private String newValue;

  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="TICKET_ID")
  private TopicEntity topic;

  public LogEntity() {
  }

  public LogEntity(LogType type, String userID, Calendar when, String originalValue, String newValue, TopicEntity topic) {
    this.type = type;
    this.userID = userID;
    this.when = when;
    this.originalValue = originalValue;
    this.newValue = newValue;
    this.topic = topic;
  }
}
