package com.yonge.cooleshow.biz.dal.wrapper;

import com.alibaba.fastjson.JSON;
import com.microsvc.toolkit.common.response.paging.QueryInfo;
import com.microsvc.toolkit.common.webportal.validation.annotation.EnumValidation;
import com.yonge.cooleshow.common.enums.EImportType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Optional;

@Data
public class FileImportInfoWrapper {


    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" FileImportInfoQuery-文件数据导入")
    public static class FileImportInfoQuery implements QueryInfo {

        @ApiModelProperty("当前页")
        private Integer page;

        @ApiModelProperty("分页行数")
        private Integer rows;

        @ApiModelProperty("关键字匹配")
        private String keyword;

        public String getKeyword() {
            return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
        }

        public String jsonString() {
            return JSON.toJSONString(this);
        }

        public static FileImportInfoQuery from(String json) {
            return JSON.parseObject(json, FileImportInfoQuery.class);
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @ApiModel(" FileImportInfo-文件数据导入")
    public static class FileImportInfo {

        @ApiModelProperty("主键ID")
        private Long id;

        @ApiModelProperty("数据类型")
        private EImportType dataType;

        @ApiModelProperty("导入文件名")
        private String fileName;

        @ApiModelProperty("导入文件地址")
        private String importUrl;

        @ApiModelProperty("导入总行数")
        private Integer totalRow;

        @ApiModelProperty("无效记录")
        private Integer invalidRow;

        @ApiModelProperty("数据入库")
        private Integer insertRow;

        @ApiModelProperty("回执文件地址")
        private String respUrl;

        @ApiModelProperty("导入帐号")
        private Long sysAccId;

        @ApiModelProperty("导入时间")
        private Date importTime;

        @ApiModelProperty("导入完成时间")
        private Date finishTime;

        @ApiModelProperty("创建时间")
        private Date createdTime;

        public String jsonString() {
            return JSON.toJSONString(this);
        }

        public static FileImportInfo from(String json) {
            return JSON.parseObject(json, FileImportInfo.class);
        }


        public FileImportInfo sysAccId(String sysAccId) {
            this.sysAccId = Long.parseLong(sysAccId);
            return this;
        }

        public FileImportInfo totalRow(Integer totalRow) {
            this.totalRow = totalRow;
            return this;
        }

        public FileImportInfo invalidRow(Integer invalidRow) {
            this.invalidRow = invalidRow;
            return this;
        }

        public FileImportInfo insertRow(Integer insertRow) {
            this.insertRow = insertRow;
            return this;
        }

        public FileImportInfo respUrl(String respUrl) {
            this.respUrl = respUrl;
            return this;
        }

        public FileImportInfo importTime(Date importTime) {
            this.importTime = importTime;
            return this;
        }

        public FileImportInfo finishTime(Date finishTime) {
            this.finishTime = finishTime;
            return this;
        }
    }

    @Data
    @ApiModel(" FileImport-文件数据导入")
    public static class FileImport {


        @EnumValidation(clazz = EImportType.class, message = "数据类型不正确")
        @ApiModelProperty("数据类型")
        private EImportType dataType;

        @NotNull(message = "文件名不能为空")
        @ApiModelProperty("导入文件名")
        private String fileName;

        @NotNull(message = "文件地址不能为空")
        @ApiModelProperty("导入文件地址")
        private String importUrl;

        @ApiModelProperty("导入帐号")
        private Long sysAccId;

        public String jsonString() {
            return JSON.toJSONString(this);
        }

        public static FileImportInfo from(String json) {
            return JSON.parseObject(json, FileImportInfo.class);
        }
    }

}
