Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

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

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

/**
 * One question on the first-call checklist (SOP §9 Path A step 2).
 *
 * <p>The question set is data, not code: the screen renders whatever rows are active here, in
 * {@code sortOrder}, so the script can be reworded or extended without a deploy.
 *
 * <p>Retire a question by clearing {@code active}, never by deleting the row — answers reference it,
 * and a deleted question would orphan everything ever recorded against it.
 */
@Entity
@Table(name = "user.lead_call_question")
public class LeadCallQuestion {

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

    @Column(name = "sort_order")
    private int sortOrder;

    @Column(name = "prompt")
    private String prompt;

    /** TEXT | NUMBER | YESNO | CHOICE. */
    @Column(name = "answer_type")
    private String answerType;

    /** Pipe-separated options for CHOICE, e.g. {@code Yes|No|Not sure}. Null for other types. */
    @Column(name = "choices")
    private String choices;

    @Column(name = "required")
    private boolean required;

    /** Score contributed when this question is answered. */
    @Column(name = "points")
    private int points;

    /**
     * Pipe-separated {@code LeadStage} names this question applies to, e.g.
     * {@code NEW|ASSIGNED|CONTACTED}. Empty or null means every stage.
     */
    @Column(name = "stages")
    private String stages;

    @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 getSortOrder() { return sortOrder; }
    public void setSortOrder(int sortOrder) { this.sortOrder = sortOrder; }

    public String getPrompt() { return prompt; }
    public void setPrompt(String prompt) { this.prompt = prompt; }

    public String getAnswerType() { return answerType; }
    public void setAnswerType(String answerType) { this.answerType = answerType; }

    public String getChoices() { return choices; }
    public void setChoices(String choices) { this.choices = choices; }

    public boolean isRequired() { return required; }
    public void setRequired(boolean required) { this.required = required; }

    public int getPoints() { return points; }
    public void setPoints(int points) { this.points = points; }

    public String getStages() { return stages; }
    public void setStages(String stages) { this.stages = stages; }

    /** Does this question apply at {@code stage}? An empty stage list means "everywhere". */
    public boolean appliesTo(String stage) {
        if (stages == null || stages.trim().isEmpty()) {
            return true;
        }
        if (stage == null) {
            return false;
        }
        for (String s : stages.split("\\|")) {
            if (s.trim().equalsIgnoreCase(stage.trim())) {
                return true;
            }
        }
        return false;
    }

    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; }
}