package com.bsentity.dto;

import lombok.Data;

import java.util.*;

/**
 * 附件id
 *
 * @author Trj
 */
@Data
public class FileIdDto {

    /**
     * word附件id
     */
    private String wordId;

    /**
     * pdf附件id
     */
    private String pdfId;


    /**
     * 表单id
     */
    private String formId;


    /**
     * 标识
     */
    private String flag;


    /**
     * 水印
     */
    private String watermark;


    /**
     * 水印时间
     */
    private Date watermarkDate;

    /***
     * 因为 表单中会上传多个附件。
     * 其次 附件存储 格式    文件名.格式 + -;- + 附件id +,+ 附件id
     *
     * 所以需要处理下 ， 先 “,” 号 分割, 再对数组[0] 用 “-;-” 分割。拿到 数组2[1]中的id
     *
     * @return Map<String, List < String>>  Map<文件格式 ， List<文件id>>
     */
    public Map<String, List<String>> ids() {
        this.wordId = this.wordId == null ? "" : this.wordId;
        this.pdfId = this.pdfId == null ? "" : this.pdfId;

        String wordFileIds = this.wordId;
        String pdfFileIds = this.pdfId;

        Map<String, List<String>> fileIdMap = new HashMap<>();

        if (!"".equals(pdfFileIds) && !"".equals(wordFileIds)) {
            String[] wordIds = wordFileIds.split("-;-");
            String[] wId = wordIds[1].split(",");
            List<String> wIds = Arrays.asList(wId);

            fileIdMap.put("word", wIds);

            String[] pdfIds = pdfFileIds.split("-;-");
            String[] pId = pdfIds[1].split(",");
            List<String> pIds = Arrays.asList(pId);
            fileIdMap.put("pdf", pIds);
            return fileIdMap;
        }else if (!"".equals(pdfFileIds)){
            String[] pdfIds = pdfFileIds.split("-;-");
            String[] pId = pdfIds[1].split(",");
            List<String> pIds = Arrays.asList(pId);
            fileIdMap.put("pdf", pIds);
            return fileIdMap;
        } else if (!"".equals(wordFileIds)) {
            String[] wordIds = wordFileIds.split("-;-");
            String[] wId = wordIds[1].split(",");
            List<String> wIds = Arrays.asList(wId);

            fileIdMap.put("word", wIds);

        }

        return fileIdMap;
    }

}
