content: /* 
   * SnapAdmin - An automatically generated CRUD admin UI for Spring Boot apps
   * Copyright (C) 2023 Ailef (http://ailef.tech)
   * 
  
   */
  
  
  package tech.ailef.snapadmin.internal.model;
  
  import java.time.LocalDateTime;
  
  import org.springframework.format.datetime.standard.DateTimeFormatterFactory;
  
  import jakarta.persistence.Column;
  import jakarta.persistence.Entity;
  import jakarta.persistence.GeneratedValue;
  import jakarta.persistence.GenerationType;
  import jakarta.persistence.Id;
  import jakarta.persistence.Lob;
  
  /**
   * An write operation executed by a user from the web UI. This class
   * only holds metadata about the operation and not anything
   * concrete yet (e.g. a diff or SQL query) about what change was performed. 
   */
  @Entity
  public class UserAction {
  	@Id
  	@GeneratedValue(strategy = GenerationType.IDENTITY)
  	private Integer id;
  
  	/**
  	 * The time at which the operation was perfomed
  	 */
  	@Column(nullable = false)
  	private LocalDateTime createdAt;
  	
  	/**
  	 * The SQL query generated by the operation.
  	 * This field is here but it's NOT currently supported
  	 */
  	@Lob
  	@Column(nullable = false)
  	private String sql;
  	
  	/**
  	 * The full qualified name of the Entity class this operation
  	 * occurred on.
  	 */
  	@Column(nullable = false)
  	private String javaClass;
  	
  	/**
  	 * The table name of the Entity class this operation occurred on.
  	 */
  	@Column(nullable = false)
  	private String onTable;
  	
  	@Column(nullable = false)
  	private String primaryKey;
  
  	/**
  	 * The action type (EDIT, CREATE or DELETE)
  	 */
  	@Column(nullable = false)
  	private String actionType;
  	
  	@Column(nullable = true)
  	private String username;
  	
  	public UserAction() {
  	}
  	
  	public UserAction(String onTable, String primaryKey, String actionType, String javaClass, String username) {
  		this.createdAt = LocalDateTime.now();
  		this.sql = "SQL TODO";
  		this.javaClass = javaClass;
  		this.onTable = onTable;
  		this.actionType = actionType;
  		this.primaryKey = primaryKey;
  		this.username = username;
  	}
  
  	public Integer getId() {
  		return id;
  	}
  
  	public void setId(Integer id) {
  		this.id = id;
  	}
  
  	public LocalDateTime getCreatedAt() {
  		return createdAt;
  	}
  
  	public void setCreatedAt(LocalDateTime createdAt) {
  		this.createdAt = createdAt;
  	}
  
  	public String getSql() {
  		return sql;
  	}
  
  	public void setSql(String sql) {
  		this.sql = sql;
  	}
  
  	public String getOnTable() {
  		return onTable;
  	}
  
  	public void setOnTable(String onTable) {
  		this.onTable = onTable;
  	}
  
  	public String getPrimaryKey() {
  		return primaryKey;
  	}
  
  	public void setPrimaryKey(String primaryKey) {
  		this.primaryKey = primaryKey;
  	}
  	
  	public String getActionType() {
  		return actionType;
  	}
  	
  	public void setActionType(String actionType) {
  		this.actionType = actionType;
  	}
  
  	public String getFormattedDate() {
  		return new DateTimeFormatterFactory("YYYY-MM-dd HH:mm:ss").createDateTimeFormatter().format(createdAt);
  	}
  	
  	public String getJavaClass() {
  		return javaClass;
  	}
  
  	public void setJavaClass(String javaClass) {
  		this.javaClass = javaClass;
  	}
  	
  	public String getUsername() {
  		return username;
  	}
  	
  	public void setUsername(String username) {
  		this.username = username;
  	}
  	
  
  }
  