/*
 * Arrebol Consultancy copyright
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.apc.model.core;

import com.arrebol.apc.model.admin.MoneyDaily;
import com.arrebol.apc.model.admin.OtherExpense;
import com.arrebol.apc.model.admin.Transfer;
import com.arrebol.apc.model.enums.ActiveStatus;
import com.arrebol.apc.model.enums.ApplicationOwner;
import com.arrebol.apc.model.enums.UserStatus;
import com.arrebol.apc.model.enums.UserType;
import com.arrebol.apc.model.gasoline.Gasoline;
import com.arrebol.apc.model.loan.Delivery;
import com.arrebol.apc.model.loan.LoanByUser;
import com.arrebol.apc.model.loan.LoanDetails;
import com.arrebol.apc.model.loan.LoanFeeNotification;
import com.arrebol.apc.model.mobile.preference.UserMobilePreference;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Entity
@Table(name = "APC_USER")
public class User implements Serializable {

    private static final long serialVersionUID = 5293919946950359645L;

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "id", length = 36)
    private String id;

    @OneToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "id_human_resource",
            referencedColumnName = "id",
            nullable = false
    )
    private HumanResource humanResource;

    @Column(name = "user_name", length = 100, nullable = false)
    private String userName;

    @Column(name = "pwd", length = 100, nullable = false)
    private String password;

    @Enumerated(EnumType.STRING)
    @Column(name = "user_type", nullable = false)
    private UserType userType;

    @Enumerated(EnumType.STRING)
    @Column(name = "user_status", nullable = false)
    private UserStatus userStatus;

    @Enumerated(EnumType.STRING)
    @Column(name = "application_owner", nullable = false)
    private ApplicationOwner applicationOwner;

    @Enumerated(EnumType.STRING)
    @Column(name = "certifier", nullable = false)
    private ActiveStatus certifier;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "management", nullable = false)
    private ActiveStatus management;

    @Column(name = "created_by", nullable = false, length = 36)
    private String createdBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_on", length = 19)
    private Date createdOn;

    @Column(name = "last_updated_by", length = 36)
    private String lastUpdatedBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_updated_on", length = 19)
    private Date lastUpdatedOn;

    @OneToMany(
            mappedBy = "user",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL,
            orphanRemoval = true
    )
    private List<UserByOffice> userByOffices;

    @OneToMany(
            mappedBy = "user",
            fetch = FetchType.LAZY,
            cascade = CascadeType.ALL,
            orphanRemoval = true
    )
    private List<UserMobilePreference> userMobilePreferences;

    @OneToMany(
            mappedBy = "user",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<LoanDetails> loanDetailses;

    @OneToMany(
            mappedBy = "user",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<LoanByUser> loanByUsers;

    @OneToMany(
            mappedBy = "user",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<LoanFeeNotification> loanFeeNotifications;

    @OneToMany(
            mappedBy = "userTransmitter",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<Transfer> userTransmitters;

    @OneToMany(
            mappedBy = "userReceiver",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<Transfer> userReceivers;

    @OneToMany(
            mappedBy = "user",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<MoneyDaily> moneyDailys;

    @OneToMany(
            mappedBy = "user",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<Delivery> deliverys;

    @OneToMany(
            mappedBy = "user",
            cascade = CascadeType.ALL,
            fetch = FetchType.LAZY,
            orphanRemoval = true
    )
    private List<OtherExpense> otherExpenses;

    @OneToMany(
            fetch = FetchType.LAZY,
            mappedBy = "user",
            orphanRemoval = true,
            cascade = CascadeType.ALL
    )
    private List<Gasoline> gasolines;

    public User() {
    }

    public User(String id) {
        this.id = id;
    }

    /**
     *
     * @param id
     * @param userName
     */
    public User(String id, String userName) {
        this.id = id;
        this.userName = userName;
    }

    /**
     *
     * @param id
     * @param userName
     * @param humanResource
     */
    public User(String id, String userName, HumanResource humanResource) {
        this.id = id;
        this.userName = userName;
        this.humanResource = humanResource;
    }

    /**
     *
     * @param id
     * @param humanResource
     * @param userName
     * @param certifier
     * @param userType
     */
    public User(String id, HumanResource humanResource, String userName, ActiveStatus certifier, UserType userType,ActiveStatus management) {
        this.id = id;
        this.humanResource = humanResource;
        this.userName = userName;
        this.certifier = certifier;
        this.userType = userType;
        this.management = management;
    }

    public String getId() {
        return id;
    }

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

    public HumanResource getHumanResource() {
        return humanResource;
    }

    public void setHumanResource(HumanResource humanResource) {
        this.humanResource = humanResource;
    }

    public String getUserName() {
        return userName;
    }

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

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    public UserStatus getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(UserStatus userStatus) {
        this.userStatus = userStatus;
    }

    public ApplicationOwner getApplicationOwner() {
        return applicationOwner;
    }

    public void setApplicationOwner(ApplicationOwner applicationOwner) {
        this.applicationOwner = applicationOwner;
    }

    public ActiveStatus getCertifier() {
        return certifier;
    }

    public void setCertifier(ActiveStatus certifier) {
        this.certifier = certifier;
    }
    
    public ActiveStatus getManagement() {
        return management;
    }

    public void setManagement(ActiveStatus management) {
        this.management = management;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public String getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(String lastUpdatedBy) {
        this.lastUpdatedBy = lastUpdatedBy;
    }

    public Date getLastUpdatedOn() {
        return lastUpdatedOn;
    }

    public void setLastUpdatedOn(Date lastUpdatedOn) {
        this.lastUpdatedOn = lastUpdatedOn;
    }

    public List<UserByOffice> getUserByOffices() {
        return userByOffices;
    }

    public void setUserByOffices(List<UserByOffice> userByOffices) {
        this.userByOffices = userByOffices;
    }

    public List<UserMobilePreference> getUserMobilePreferences() {
        return userMobilePreferences;
    }

    public void setUserMobilePreferences(List<UserMobilePreference> userMobilePreferences) {
        this.userMobilePreferences = userMobilePreferences;
    }

    public List<LoanDetails> getLoanDetailses() {
        return loanDetailses;
    }

    public void setLoanDetailses(List<LoanDetails> loanDetailses) {
        this.loanDetailses = loanDetailses;
    }

    public List<LoanByUser> getLoanByUsers() {
        return loanByUsers;
    }

    public void setLoanByUsers(List<LoanByUser> loanByUsers) {
        this.loanByUsers = loanByUsers;
    }

    public List<LoanFeeNotification> getLoanFeeNotifications() {
        return loanFeeNotifications;
    }

    public void setLoanFeeNotifications(List<LoanFeeNotification> loanFeeNotifications) {
        this.loanFeeNotifications = loanFeeNotifications;
    }

    public List<Transfer> getUserTransmitters() {
        return userTransmitters;
    }

    public void setUserTransmitters(List<Transfer> userTransmitters) {
        this.userTransmitters = userTransmitters;
    }

    public List<Transfer> getUserReceivers() {
        return userReceivers;
    }

    public void setUserReceivers(List<Transfer> userReceivers) {
        this.userReceivers = userReceivers;
    }

    public List<MoneyDaily> getMoneyDailys() {
        return moneyDailys;
    }

    public void setMoneyDailys(List<MoneyDaily> moneyDailys) {
        this.moneyDailys = moneyDailys;
    }

    public List<Delivery> getDeliverys() {
        return deliverys;
    }

    public void setDeliverys(List<Delivery> deliverys) {
        this.deliverys = deliverys;
    }

    public List<OtherExpense> getOtherExpenses() {
        return otherExpenses;
    }

    public void setOtherExpenses(List<OtherExpense> otherExpenses) {
        this.otherExpenses = otherExpenses;
    }

    public List<Gasoline> getGasolines() {
        return gasolines;
    }

    public void setGasolines(List<Gasoline> gasolines) {
        this.gasolines = gasolines;
    }

    @Override
    public String toString() {
        return "User{" + "userName=" + userName + '}';
    }
}
