package com.yunyan.business.pojo.admin.dto;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collections;

/**
 * 决算excel 数据的读取 dto
 */
@Data
public class FinalImportExcelDto {

    @ApiModelProperty(value = "类型: 1-决算, 2-预算, 默认1", hidden = true)
    private Integer type;

    @NotBlank(message = "年份必传")
    @ApiModelProperty(value = "年份(决算取取去年年份, 预算去本年年份)", required = true)
    private String year;

    //@NotBlank(message = "预算类型时-区域必传")
    @ApiModelProperty(value = "区域", required = true)
    private String area;

    //lastYearFlag 改为 dataType
    @NotNull(message = "数据类型的标记必传")
    @ApiModelProperty(value = "0-本年决算, 1-去年决算, 2-本年预算 本年的年份是0, 上一年的年份传1", required = true)
    private Integer dataType;

    //TODO 改成 list类型
    @NotBlank(message = "服务器保存的路径文件名必传")
    @ApiModelProperty(value = "服务器保存的路径文件名", required = true)
    private String fileNames;

    //@NotBlank(message = "服务器保存的路径文件名必传")
    @ApiModelProperty(value = "服务器保存的文件名", required = true)
    private String newFileNames;

    @NotBlank(message = "上传的原文件名必传")
    @ApiModelProperty(value = "上传的原文件名", required = true)
    private String originalFilenames;

    @ApiModelProperty(value = "是否更新支持， 1-是， 0-否", hidden = true)
    private In updateSupport;

    @ApiModelProperty(value = "单位名的确定类型(去年数据导入): 1-excel中的编制单位, 2-excel文件名, 默认1")
    private Integer deptNameBy = 1;

    @ApiModelProperty(value = "服务器保存的路径文件名List")
    private ArrayList< String> fileNamesList;

    @ApiModelProperty(value = "上传的原文件名 list")
    private ArrayList< String> originalFilenamesList;

    public ArrayList<String> getFileNamesList() {
        if(StringUtils.isBlank(fileNames)) {
            return new ArrayList<>();
        }

        String[] fileNamesArray = fileNames.split(",");
        //数组转 list
        ArrayList< String> list = new ArrayList<>(fileNamesArray.length);
        Collections.addAll(list, fileNamesArray);

        this.fileNamesList = list;
        return list;
    }

    public ArrayList<String> getOriginalFilenamesList() {
        if(StringUtils.isBlank(originalFilenames)) {
            return new ArrayList<>();
        }

        String[] originalFilenamesArray = originalFilenames.split(",");
        //数组转 list
        ArrayList< String> list = new ArrayList<>(originalFilenamesArray.length);
        Collections.addAll(list, originalFilenamesArray);

        this.originalFilenamesList = list;
        return list;
    }
}
