/*
 * This file is part of DebGen Biobank Software developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 * Copyright ASTRID Research Inc., Hungary, 2009-2011.
 *
 * ASTRID Research
 * Headquaters: Csapo utca 42. Debrecen H-4029 HUNGARY
 * Phone: +36-52-533-173        Fax: +36-52-533-174
 * Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DebGen Biobank Software project.
 * URLS:
 * Developers: Istvan Zoltan Nagy (istvan.nagy@astrid.hu)
 */
package hu.astrid.debgen.forgottenpassword.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Random;
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.Transient;

/**
 * Object of forgotten password entries
 * @author inagy
 */
@Entity
@Table(name="debgen_forgottenpassword")
public class ForgottenPasswordEntry implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Transient
    private Random r = new Random(new Date().getTime());
    private String userName;    //Use DeBGenUser instance instead of a String
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date requestTime;
    private String confirmCode;
    private String cancelCode;
    
    public ForgottenPasswordEntry() {
    }

    private String generateCode() {
        return Long.toHexString(r.nextLong());
    }

    /**
     * Sets all fields of this Forgottenpassword instance with the specified userName
     * @param userName The name of the user
     */
    public void create(String userName) {
        this.setUserName(userName);
        this.setRequestTime(new Date());
        this.setConfirmCode(generateCode());
        this.setCancelCode(generateCode());
    }

    public String getUserName() {
        return userName;
    }

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

    /**
     * @return the requestTime
     */
    public Date getRequestTime() {
        return requestTime;
    }

    /**
     * @param requestTime the requestTime to set
     */
    public void setRequestTime(Date requestTime) {
        this.requestTime = requestTime;
    }

    /**
     * @return the confirmCode
     */
    public String getConfirmCode() {
        return confirmCode;
    }

    /**
     * @param confirmCode the confirmCode to set
     */
    public void setConfirmCode(String confirmCode) {
        this.confirmCode = confirmCode;
    }

    /**
     * @return the cancelCode
     */
    public String getCancelCode() {
        return cancelCode;
    }

    /**
     * @param cancelCode the cancelCode to set
     */
    public void setCancelCode(String cancelCode) {
        this.cancelCode = cancelCode;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }
}
