/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package kr.co.kihyun.service.vo;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jdo.PersistenceManager;
import javax.jdo.annotations.Serialized;
import kr.co.kihyun.beans.entity.AssignType;
import kr.co.kihyun.beans.entity.Foundation;
import kr.co.kihyun.beans.entity.Grade;
import kr.co.kihyun.beans.entity.Recog;
import kr.co.kihyun.beans.entity.TotDoc;
import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.entity.TotReportProcess;
import kr.co.kihyun.beans.entity.TotReportType;
import kr.co.kihyun.io.IUploadable;
import kr.co.kihyun.service.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author KWON.HAN
 */
public class PrssReportsVO {
    private static final Logger LOG = LoggerFactory.getLogger(BaseService.class);

    private String deptNo;
    private Long docId;
    private Long id;
    private String ownerName;
    private String ownerPhone;
    private AssignType assignType = AssignType.ASSIGN_TO_DEPT;
    private Integer docType;
    private String delType;

    private String deptId;
    private String userId;

    private TotReportProcess process = TotReportProcess.ACCEPT;
    private Integer prss;

    private TotDoc slaveTotDoc;
    private Long downDocId;

    private Recog recogType = Recog.NOT_RECOG;
    private Integer recog;

    private Date submitDate;

    private TotReportType reportType = TotReportType.REPORT;
    private Integer type;

    private String deptName;

    private Integer grade;
    private Integer foundation;
    private Grade gradeType = Grade.NULL;
    private Foundation foundationType = Foundation.NULL;
    private String organ;
    private String organName;
    private String upperDept;
    private String upperDeptName;
    private String deptPhone;

    private String userPhone;
    private Long rowNo;

    private String isAttachments;
    @Serialized
    private Map<String, List<Byte>> attachmentsMap;
    private String isNote;
    private String noteString;
    private String attachmentsPath;


    public String getDeptNo() {
        return deptNo;
    }

    public void setDeptNo(String deptNo) {
        this.deptNo = deptNo;
    }

    public Long getDocId() {
        return docId;
    }

    public void setDocId(Long docId) {
        this.docId = docId;
    }

    public Long getId() {
        return id;
    }

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

    public String getOwnerName() {
        return ownerName;
    }

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;
    }

    public String getOwnerPhone() {
        return ownerPhone;
    }

    public void setOwnerPhone(String ownerPhone) {
        this.ownerPhone = ownerPhone;
    }

    public AssignType getAssignType() {
        this.assignType = AssignType.values()[this.docType];
        return this.assignType;
    }

    public Integer getDocType() {
        return docType;
    }

    public void setDocType(Integer docType) {
        this.docType = docType;
    }

    public String getDelType() {
        return delType;
    }

    public void setDelType(String delType) {
        this.delType = delType;
    }

    public boolean isDeleted() {
        return this.getDelType().equals("Y");
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public TotReportProcess getProcess() {
        this.process = TotReportProcess.values()[this.prss];
        return this.process;
    }

    public Integer getPrss() {
        return prss;
    }

    public void setPrss(Integer prss) {
        this.prss = prss;
    }


    public TotDoc getSlaveTotDoc(PersistenceManager pm) {
        if(this.downDocId == null) {
            this.slaveTotDoc = null;
        } else {
            this.slaveTotDoc = pm.getObjectById(TotDoc.class, this.downDocId);
        }

        return this.slaveTotDoc;
    }

    public Long getDownDocId() {
        return downDocId;
    }

    public void setDownDocId(Long downDocId) {
        this.downDocId = downDocId;
    }


    public Recog getRecogType() {
        this.recogType = Recog.values()[this.recog];
        return this.recogType;
    }

    public Integer getRecog() {
        return recog;
    }

    public void setRecog(Integer recog) {
        this.recog = recog;
    }

    public Date getSubmitDate() {
        return submitDate;
    }

    public void setSubmitDate(Date submitDate) {
        this.submitDate = submitDate;
    }

    public TotReportType getReportType() {
        this.reportType = TotReportType.values()[this.prss];
        return this.reportType;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public Integer getGrade() {
        return grade;
    }

    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    public Grade getGradeType(){
        if(this.grade == null){
            this.gradeType = Grade.values()[0];
        }else{
            this.gradeType = Grade.values()[this.grade];
        }
        return this.gradeType;
    }

    public Integer getFoundation() {
        return foundation;
    }

    public void setFoundation(Integer foundation) {
        this.foundation = foundation;
    }

    public Foundation getFoundationType() {
        if(this.foundation == null) {
            this.foundationType = Foundation.values()[0];
        } else {
            this.foundationType = Foundation.values()[this.foundation];
        }

        return this.foundationType;
    }

    public String getOrgan() {
        return organ;
    }

    public void setOrgan(String organ) {
        this.organ = organ;
    }

    public String getOrganName() {
        return organName;
    }

    public void setOrganName(String organName) {
        this.organName = organName;
    }

    public String getUpperDept() {
        return upperDept;
    }

    public void setUpperDept(String upperDept) {
        this.upperDept = upperDept;
    }

    public String getUpperDeptName() {
        return upperDeptName;
    }

    public void setUpperDeptName(String upperDeptName) {
        this.upperDeptName = upperDeptName;
    }

    public String getDeptPhone() {
        return deptPhone;
    }

    public void setDeptPhone(String deptPhone) {
        this.deptPhone = deptPhone;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public Long getRowNo() {
        return rowNo;
    }

    public void setRowNo(Long rowNo) {
        this.rowNo = rowNo;
    }

    public String getIsAttachments() {
        return isAttachments;
    }

    public void setIsAttachments(String isAttachments) {
        this.isAttachments = isAttachments;
    }

    public String getAttachmentsPath() {
        return attachmentsPath;
    }

    public void setAttachmentsPath(String attachmentsPath) {
        this.attachmentsPath = attachmentsPath;
    }


    public Map<String, List<Byte>> getAttachmentsMap(PersistenceManager pm) {

        if("Y".equals(this.isAttachments)) {
            Long reportID = this.id;
            IUploadable uploadable = pm.getObjectById(TotReport.class, reportID);
            this.attachmentsMap = uploadable.getAttachments();
        } else {
            this.attachmentsMap = Collections.unmodifiableMap(new HashMap<String, List<Byte>>());
        }

        return attachmentsMap;
    }

    public String getIsNote() {
        return isNote;
    }

    public void setIsNote(String isNote) {
        this.isNote = isNote;
    }

    public String getNoteString(PersistenceManager pm) {

        if("Y".equals(this.isNote)) {
            Long reportID = this.id;
            TotReport report = pm.getObjectById(TotReport.class, reportID);
            this.noteString = report.getNote();
        } else {
            this.noteString = null;
        }

        return noteString;
    }


}
