package com.capgemini.reports.users;

import com.capgemini.framework.teamcenter.authent.TcSession;
import com.teamcenter.soa.client.model.strong.Person;
import com.teamcenter.soa.client.model.strong.User;

import java.io.Serializable;

/**
 * Represents a TC User.
 */
public class SnecmaUser implements Serializable {
    private static final long serialVersionUID = -4311528092285199052L;

    private static final long ACTIVE_STATUS = 0; // TC code for active status is '0'
    private final TcSession session;
    private final User user;

    /**
     * Builds a TC {@link User}.
     */
    public SnecmaUser(final TcSession session, final User user) {
        this.session = session;
        this.user = user;
    }

    public String getName() {
        return user.get_user_name();
    }

    public String getUserId() {
        return user.get_user_id();
    }

    public SnecmaPerson getPerson() {
        session.loadProperties(user, "person");
        Person person = user.get_person();
        session.loadProperties(person);
        return new SnecmaPerson(person);
    }

    /**
     * The values are 1 ("inactif") and 0 ("actif").
     */
    public boolean isActive() {
        return user.get_status() == ACTIVE_STATUS;
    }

    @Override
    public String toString() {
        return "User " + getName() + " ID=" + getUserId();
    }
}
