package com.sdtool.common.entity.base;

import com.sdtool.common.entity.site.ERPTokenUser;
import com.sweetfish.convert.json.JsonConvert;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by jlutt on 2020-08-11
 *
 * @author jlutt
 */
public class ProcessEntityItem<T extends BaseEntity> extends BaseEntity {

    private T inputItem;

    private BusinessOperation operation;

    private ERPTokenUser currentUser;

    private String dataSourceId;

    private long supplierCode;

    private final Map<String, JsonConvert> jsonConvertMap = new HashMap<>();

    public ProcessEntityItem() {
    }

    private ProcessEntityItem(Builder<T> builder) {
        setCreateBy(builder.createBy);
        setCreateTime(builder.createTime);
        setCreateTimeLong(builder.createTimeLong);
        setUpdateBy(builder.updateBy);
        setUpdateTime(builder.updateTime);
        setUpdateTimeLong(builder.updateTimeLong);
        setInputItem(builder.inputItem);
        setOperation(builder.operation);
        setDataSourceId(builder.dataSourceId);
        setSupplierCode(builder.supplierCode);
        setCurrentUser(builder.currentUser);
    }

    public ProcessEntityItem<T> addConvert(String name, JsonConvert jsonConvert) {
        this.jsonConvertMap.put(name, jsonConvert);
        return this;
    }

    public JsonConvert getConvert(String name) {
        return jsonConvertMap.get(name);
    }

    public static <T extends BaseEntity> Builder<T> newBuilder() {
        return new Builder<>();
    }


    public T getInputItem() {
        return inputItem;
    }

    public void setInputItem(T inputItem) {
        this.inputItem = inputItem;
    }

    public BusinessOperation getOperation() {
        return operation;
    }

    public void setOperation(BusinessOperation operation) {
        this.operation = operation;
    }

    public String getDataSourceId() {
        return dataSourceId;
    }

    public void setDataSourceId(String dataSourceId) {
        this.dataSourceId = dataSourceId;
    }

    public long getSupplierCode() {
        return supplierCode;
    }

    public void setSupplierCode(long supplierCode) {
        this.supplierCode = supplierCode;
    }

    public ERPTokenUser getCurrentUser() {
        return currentUser;
    }

    public void setCurrentUser(ERPTokenUser currentUser) {
        this.currentUser = currentUser;
    }

    public static final class Builder<T extends BaseEntity> {
        private long createBy;
        private Date createTime;
        private long createTimeLong;
        private long updateBy;
        private Date updateTime;
        private long updateTimeLong;
        private T inputItem;
        private BusinessOperation operation;
        private String dataSourceId;
        private long supplierCode;
        private ERPTokenUser currentUser;

        private Builder() {
        }

        public Builder<T> createBy(long val) {
            createBy = val;
            return this;
        }

        public Builder<T> createTime(Date val) {
            createTime = val;
            return this;
        }

        public Builder<T> createTimeLong(long val) {
            createTimeLong = val;
            return this;
        }

        public Builder<T> updateBy(long val) {
            updateBy = val;
            return this;
        }

        public Builder<T> updateTime(Date val) {
            updateTime = val;
            return this;
        }

        public Builder<T> updateTimeLong(long val) {
            updateTimeLong = val;
            return this;
        }

        public Builder<T> inputItem(T val) {
            inputItem = val;
            return this;
        }

        public Builder<T> operation(BusinessOperation val) {
            operation = val;
            return this;
        }

        public Builder<T> dataSourceId(String val) {
            dataSourceId = val;
            return this;
        }

        public Builder<T> supplierCode(long val) {
            supplierCode = val;
            return this;
        }

        public Builder<T> currentUser(ERPTokenUser val) {
            currentUser = val;
            return this;
        }

        public ProcessEntityItem<T> build() {
            return new ProcessEntityItem<>(this);
        }
    }
}
