package com.smppw.modaq.domain.dto;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.smppw.modaq.application.util.EmailUtil;
import com.smppw.modaq.common.conts.EmailTypeConst;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.util.List;

@Setter
@Getter
public class UploadReportParams {
    private String title;
    private List<ReportInfo> reportInfos;

    public UploadReportParams() {
        this.reportInfos = ListUtil.list(false);
    }

    @Setter
    public static class ReportInfo {
        /**
         * 报告名称
         */
        private String reportName;
        /**
         * 报告类型
         *
         * @see EmailTypeConst
         */
        private Integer reportType;
        /**
         * 报告路径，必传
         */
        private String reportPath;
        /**
         * 报告路径转file对象
         */
        private transient File reportFile;

        public String getReportName() {
            if (StrUtil.isNotBlank(this.reportName)) {
                return this.reportName;
            }
            return FileUtil.getName(this.reportFile);
        }

        public Integer getReportType() {
            if (this.reportType != null && EmailTypeConst.SUPPORT_EMAIL_TYPES.contains(this.reportType)) {
                return this.reportType;
            }
            return EmailUtil.getEmailTypeBySubject(this.reportPath);
        }

        public String getReportPath() {
            this.reportFile = FileUtil.file(reportPath);
            return reportPath;
        }

        public ReportInfo() {
        }

        public ReportInfo(String reportPath) {
            this.reportPath = reportPath;
        }
    }
}