package com.acme.model.domain.ejf.entity;


import com.acme.structure.BaseEntity;
import com.acme.structure.logger.LoggedProcess;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity(name = "Log")
@Table(name = "MAINLOGS")
//this is for oracle db @SequenceGenerator(name = "LOG_SEQ", sequenceName = "LOG_SEQ")
public class Log extends BaseEntity
{
    private String userName;
    private char process;
    private String method;
    private int versionOfEntity;
    private String entityClass;
    private long entityId;
    private String entityValue;
    private Date dateOfProcess;

    public Log()
    {
        entityName = "Log";
    }

    public Log(LoggedProcess loggedProcess)
    {
        entityName = "Log";

        setUserName(loggedProcess.getUser());
        setProcess(loggedProcess.getProcess());
        setMethod(loggedProcess.getMethod());
        setVersionOfEntity(loggedProcess.getVersion());
        setEntityClass(loggedProcess.getEntityName());
        setEntityId(loggedProcess.getEntityId());
        setEntityValue(loggedProcess.getEntityValue());
        setDateOfProcess(loggedProcess.getDateOfProcess());
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) //, this is for oracle db, generator = "LOG_SEQ")
    @Column(name = "ID")
    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    @Column(name = "USERNAME")
    public String getUserName()
    {
        return userName;
    }

    public void setUserName(String username)
    {
        this.userName = username;
    }

    @Column(name = "PROCESS")
    public char getProcess()
    {
        return process;
    }

    public void setProcess(char process)
    {
        this.process = process;
    }

    @Column(name = "METHOD")
    public String getMethod()
    {
        return method;
    }

    public void setMethod(String method)
    {
        this.method = method;
    }

    @Column(name = "VERSIONOFENTITY")
    public int getVersionOfEntity()
    {
        return versionOfEntity;
    }

    public void setVersionOfEntity(int versionOfEntity)
    {
        this.versionOfEntity = versionOfEntity;
    }

    @Column(name = "ENTITYCLASS")
    public String getEntityClass()
    {
        return entityClass;
    }

    public void setEntityClass(String entityClass)
    {
        this.entityClass = entityClass;
    }

    @Column(name = "ENTITYID")
    public long getEntityId()
    {
        return entityId;
    }

    public void setEntityId(long entityId)
    {
        this.entityId = entityId;
    }

    @Column(name = "ENTITYVALUE")
    public String getEntityValue()
    {
        return entityValue;
    }

    public void setEntityValue(String entityValue)
    {
        this.entityValue = entityValue;
    }

    @Column(name = "DATEOFPROCESS")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getDateOfProcess()
    {
        return dateOfProcess;
    }

    public void setDateOfProcess(Date dateOfProcess)
    {
        this.dateOfProcess = dateOfProcess;
    }

    public String toString()
    {
        return getUserName() + " - " + getDateOfProcess() + " - " + getEntityClass() + " - " + getEntityValue();
    }
}
