package cn.estsh.i3plus.pojo.softswitch.bean;

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.BlockSoftSwitchEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-09-25 17:43
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "BS_SUIT_CASE_FTP")
@Api(value = "FTP适配器", description = "FTP适配器")
public class BsSuitCaseFTP extends BaseBean {

    private static final long serialVersionUID = 6174265510888236886L;
    @Column(name = "SUIT_CASE_ID")
    @ApiParam(value = "套件id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitCaseId;

    @Column(name = "File_Name")
    @ApiParam(value = "文件名")
    private String fileName;

    @Column(name = "FILE_ENCODE")
    @ApiParam(value = "文件编码")
    private Integer fileEncode;

    @Column(name = "IS_TRANSFORM_MESSAGE")
    @ApiParam(value = "是否转换报文")
    @AnnoOutputColumn(refClass = CommonEnumUtil.TRUE_OR_FALSE.class)
    private Integer isTransformMessage;

    public int getIsTransformMessageVal() {
        return isTransformMessage == null ? CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue() : isTransformMessage;
    }

    public boolean isTransformMessage() {
        return CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(getIsTransformMessageVal());
    }


    @Column(name = "ENCODE")
    @ApiParam(value = "ftp编码")
    private Integer encode;

    @Column(name = "CONNECTION_MODE")
    @ApiParam(value = "ftp连接模式")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.FTP_CONNECTION_MODE.class)
    private Integer connectionMode;

    public String getConnectionModeTxt(){
        return connectionMode == null ? "无" : BlockSoftSwitchEnumUtil.FTP_CONNECTION_MODE.valueOfDescription(connectionMode);
    }

    @Column(name = "IS_READ_AND_EMPTY")
    @ApiParam(value = "读取并清空")
    private Integer isReadAndEmpty;

    public boolean isReadAndEmpty() {
        return CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(isReadAndEmpty);
    }

    @Column(name = "IS_READ_AND_DELETE")
    @ApiParam(value = "读取并删除")
    private Integer isReadAndDelete;

    public boolean isReadAndDelete() {
        return CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(isReadAndDelete);
    }

    @Column(name = "IS_NEED_TRAVERSAL")
    @ApiParam(value = "是否需要遍历")
    private Integer isNeedTraversal;

    public boolean isNeedTraversal() {
        return CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(isNeedTraversal);
    }

    @Column(name = "IS_INCREMENTAL_READ")
    @ApiParam(value = "是否增量读取")
    private Integer isIncrementalRead;

    public boolean isIncrementalRead() {
        return CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(isIncrementalRead);
    }

    @Column(name = "IS_INCREMENTAL_WRITE")
    @ApiParam(value = "是否增量写入")
    private Integer isIncrementalWrite;

    public int getIsIncrementalWriteVal(){
        return isIncrementalWrite == null ? CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue() : isIncrementalWrite;
    }

    public boolean isIncrementalWrite() {
        return CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(getIsIncrementalWriteVal());
    }

    @ColumnDefault("2")
    @Column(name = "IS_CHECK_FILE")
    @ApiParam(value = "是否校验文件")
    private Integer isCheckFile;

    public boolean isCheckFile(){
        return isCheckFile != null && CommonEnumUtil.TRUE_OR_FALSE.valueOfBoolean(isCheckFile);
    }

    @Column(name = "CHECK_FILE_PATH")
    @ApiParam(value = "校验文件路径")
    private String checkFilePath;

    @Transient
    @ApiParam(value = "临时适配路径")
    private String tempSuitFilePath;
    @Transient
    @ApiParam(value = "临时适配路径")
    private List<String> ftpFileList;

    @Transient
    @ApiParam(value = "适配文件列表")
    public List<BsSuitFile> bsSuitFileList;

}
