package com.ejie.ad74a.util;

import java.io.InputStream;

import org.apache.commons.lang.StringUtils;

/**
 * @author JBHG
 * 
 */
public class AttachmentBeanPIF {

    // Info del fichero
    private String path;
    private String name;
    private Long size;
    private String mimeType;
    // Bytes del fichero
    private InputStream contentInputStream;
    // Ruta en disco del fichero
    private String diskPath;

    private static final String BATCH_RETURN_SEPARATOR_CHAR = "#";

    /**
     * Sin parametros
     */
    public AttachmentBeanPIF() {
        // Constructor por defecto
    }

    /**
     * 
     * @param path
     *            String
     * @param name
     *            String
     * @param size
     *            Long
     * @param mimeType
     *            String
     */
    public AttachmentBeanPIF(String path, String name, Long size, String mimeType) {
        this.path = path;
        this.name = name;
        this.size = size;
        this.mimeType = mimeType;
    }

    /**
     * Constructor que carga los datos en base a la cadena que devuelve el
     * comando pif-batch 'info'.
     * 
     * @param infoResultCade
     *            String
     */
    public AttachmentBeanPIF(String infoResultCade) {
        if (!StringUtils.isEmpty(infoResultCade)) {
            String[] arrResult = infoResultCade.trim().replace("\n", "").split(BATCH_RETURN_SEPARATOR_CHAR);
            if (arrResult.length >= 4) {
                this.mimeType = arrResult[0];
                this.path = arrResult[1];
                this.name = arrResult[2];
                this.size = Long.valueOf(arrResult[3]);
            }
        }
    }

    /**
     * @return the path
     */
    public String getPath() {
        return path;
    }

    /**
     * @param path
     *            the path to set
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the size
     */
    public Long getSize() {
        return size;
    }

    /**
     * @param size
     *            the size to set
     */
    public void setSize(Long size) {
        this.size = size;
    }

    /**
     * @return the mimeType
     */
    public String getMimeType() {
        return mimeType;
    }

    /**
     * @param mimeType
     *            the mimeType to set
     */
    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    /**
     * @return the contentInputStream
     */
    public InputStream getContentInputStream() {
        return contentInputStream;
    }

    /**
     * @param contentInputStream
     *            the contentInputStream to set
     */
    public void setContentInputStream(InputStream contentInputStream) {
        this.contentInputStream = contentInputStream;
    }

    /**
     * @return the diskPath
     */
    public String getDiskPath() {
        return diskPath;
    }

    /**
     * @param diskPath
     *            the diskPath to set
     */
    public void setDiskPath(String diskPath) {
        this.diskPath = diskPath;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("AttachmentBeanPIF [path=").append(path).append(", name=").append(name).append(", size=")
                .append(size).append(", mimeType=").append(mimeType).append("]");
        return builder.toString();
    }

}