package faqapp.struts.forms;

import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;

import faqapp.AreaTO;
import faqapp.TopicTO;

/**
 * Struts FAQForm bean. This form has the following fields,
 * with default values in square brackets:
 * <ul>
 * <li><b>id</b> - Auto-generated FAQ ID
 * <li><b>action</b> - Form action
 * <li><b>question</b> - Entered question
 * <li><b>answer</b> - Entered answer
 * <li><b>internalFlag</b> - Selected internal flag [false]
 * <li><b>productVersion</b> - Entered product version
 * <li><b>areas</b> - Array of all Areas stored by FAQAction
 * <li><b>areaFlags</b> - Map of flags indicating selected Areas
 * <li><b>topics</b> - Array of all Topics for Areas stored by FAQAction
 * <li><b>topicIDs</b> - Map of selected topicIDs
 * </ul>
 */
public final class FAQForm extends FAQAbstractForm implements Serializable {
    private String question;
    private String answer;
    private boolean internalFlag = false;
    private String productVersion;
    private AreaTO[] areas;
    private Map areaFlags = new HashMap();
    private TopicTO[][] topics;
    private Map topicIDs = new HashMap();

    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public boolean isInternalFlag() {
        return internalFlag;
    }

    public void setInternalFlag(boolean internalFlag) {
        this.internalFlag = internalFlag;
    }

    public String getProductVersion() {
        return productVersion;
    }

    public void setProductVersion(String productVersion) {
        this.productVersion = productVersion;
    }

    public AreaTO[] getAreas() {
        return areas;
    }

    public void setAreas(AreaTO[] areas) {
        this.areas = areas;
    }

    public Map getAreaFlags() {
        return areaFlags;
    }

    public void setAreaFlags(Map areaFlags) {
        this.areaFlags = areaFlags;
    }

    public Boolean getAreaFlag(int index) {
        Boolean areaFlag = (Boolean)this.areaFlags.get(new Integer(index));
        return (areaFlag != null) ? areaFlag : new Boolean(false);
    }

    public void setAreaFlag(int index, Boolean areaFlag) {
        if (areaFlag == null) areaFlag = new Boolean(false);
        this.areaFlags.put(new Integer(index), areaFlag);
    }

    public TopicTO[][] getTopics() {
        return topics;
    }

    public void setTopics(TopicTO[][] topics) {
        this.topics = topics;
    }

    public Map getTopicIDs() {
        return topicIDs;
    }

    public void setTopicIDs(Map topicIDs) {
        this.topicIDs = topicIDs;
    }

    public Integer getTopicID(int index) {
        Integer topicID = (Integer)this.topicIDs.get(new Integer(index));
        return (topicID != null) ? topicID : new Integer(0);
    }

    public void setTopicID(int index, Integer topicID) {
        if (topicID == null) topicID = new Integer(0);
        this.topicIDs.put(new Integer(index), topicID);
    }

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset();
        question = null;
        answer = null;
        internalFlag = false;
        productVersion = null;
        areas = null;
        areaFlags.clear();
        topics = null;
        topicIDs.clear();
    }
}

