Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.entity.auth;

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.UniqueConstraint;
import java.time.LocalDateTime;

/**
 * Maps one of our {@code auth.auth_user} rows to its Vonage Application user.
 *
 * <p>The Client SDK authenticates a <em>Vonage user</em>, not our user: the JWT's {@code sub} claim
 * must be the {@code vonage_user_name} created against the Vonage Application. Without a row here an
 * agent simply cannot be issued a token, which is why the dialer disables its call button rather than
 * failing at {@code createSession}.
 *
 * <p>Deliberately a separate table from {@code auth.sip_master} even though both are "agent telephony
 * identity". {@code sip_master} is Knowlarity's, is keyed on {@code email_id}/{@code caller_id}, and is
 * read by {@code KnowlarityAgentResolver} on every live-call event — widening it for a second provider
 * would put the LMS dialer in the blast radius of the call-centre monitor.
 */
@Entity
@Table(name = "auth.vonage_agent",
        uniqueConstraints = {@UniqueConstraint(columnNames = "auth_id")})
public class VonageAgent {

    @Id
    @Column(name = "id", unique = true, updatable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(name = "auth_id")
    private int authId;

    /** Vonage's own id for the user, e.g. {@code USR-xxxxxxxx-...}. Provenance; not used in the JWT. */
    @Column(name = "vonage_user_id")
    private String vonageUserId;

    /** The name the JWT's {@code sub} claim carries. This is the one that must be right. */
    @Column(name = "vonage_user_name")
    private String vonageUserName;

    /**
     * The Vonage virtual number this agent calls out from, presented to the retailer as caller ID.
     * E.164 digits, no plus. Per-agent rather than one number for the company: agents are assigned
     * their own numbers, and the retailer's callback should reach the person who rang them.
     *
     * <p>Must be a number on the Vonage account — the Voice API rejects a {@code from} it does not
     * own. Null falls back to the {@code vonage.from.number} default.
     */
    @Column(name = "from_number")
    private String fromNumber;

    /**
     * The agent's VBC extension, e.g. {@code 1042}. This is what click2dial originates <em>from</em>:
     * VBC rings this extension's registered device and only then dials the retailer.
     *
     * <p>Distinct from {@link #fromNumber}, which is a caller-ID phone number on the Communications
     * APIs path. An extension is not a phone number and the two are not interchangeable.
     */
    @Column(name = "vbc_extension")
    private String vbcExtension;

    /**
     * A registered VBC device id, used when {@code vonage.vbc.from.type=device}.
     *
     * <p>Separate from {@link #vbcExtension} because they are different address spaces: an
     * extension is a short dialable number, a device id is an opaque handle from
     * {@code GET /telephony/v3/registration/accounts/{id}/devices}. Which one click2dial should
     * originate from is an account-shaped question, hence the config switch rather than a guess.
     */
    @Column(name = "vbc_device_id")
    private String vbcDeviceId;

    /**
     * Lets an agent be switched off without deleting the mapping — revoking dialer access while
     * keeping the audit trail's ability to explain who placed historic calls.
     */
    @Column(name = "active")
    private boolean active = true;

    @Column(name = "created_timestamp")
    private LocalDateTime createdTimestamp;

    @Column(name = "updated_timestamp")
    private LocalDateTime updatedTimestamp;

    public int getId() {
        return id;
    }

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

    public int getAuthId() {
        return authId;
    }

    public void setAuthId(int authId) {
        this.authId = authId;
    }

    public String getVonageUserId() {
        return vonageUserId;
    }

    public void setVonageUserId(String vonageUserId) {
        this.vonageUserId = vonageUserId;
    }

    public String getVonageUserName() {
        return vonageUserName;
    }

    public void setVonageUserName(String vonageUserName) {
        this.vonageUserName = vonageUserName;
    }

    public String getFromNumber() {
        return fromNumber;
    }

    public void setFromNumber(String fromNumber) {
        this.fromNumber = fromNumber;
    }

    public String getVbcExtension() {
        return vbcExtension;
    }

    public void setVbcExtension(String vbcExtension) {
        this.vbcExtension = vbcExtension;
    }

    public String getVbcDeviceId() {
        return vbcDeviceId;
    }

    public void setVbcDeviceId(String vbcDeviceId) {
        this.vbcDeviceId = vbcDeviceId;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public LocalDateTime getCreatedTimestamp() {
        return createdTimestamp;
    }

    public void setCreatedTimestamp(LocalDateTime createdTimestamp) {
        this.createdTimestamp = createdTimestamp;
    }

    public LocalDateTime getUpdatedTimestamp() {
        return updatedTimestamp;
    }

    public void setUpdatedTimestamp(LocalDateTime updatedTimestamp) {
        this.updatedTimestamp = updatedTimestamp;
    }

    @Override
    public String toString() {
        return "VonageAgent [authId=" + authId + ", vonageUserName=" + vonageUserName
                + ", fromNumber=" + fromNumber + ", active=" + active + "]";
    }
}