package link.at17.mid.tushare.data.models;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import link.at17.mid.tushare.data.typehandler.JsonListTypeHandler;
import link.at17.mid.tushare.system.util.EncryptUtils;
import lombok.Data;

@Data
public class UpdateMethodInfo {
    
    private String methodName;

    private String declaringClassName;
    
    private String name;
    
    @TableField(typeHandler = JsonListTypeHandler.class)
    private List<UpdateParamInfo> params = new ArrayList<>();
    
    private String id;
    
    public String getId() {
        if (StringUtils.isBlank(id) && !StringUtils.isAnyBlank(methodName, declaringClassName)) {
            id = EncryptUtils.sha256(declaringClassName + '$' + methodName);
        }
        return id;
    }
    
    @Data
    public static class UpdateParamInfo {
        private String fullTypeName;
        private String typeName;
        private String name;
        @JsonIgnore
        private Class<?> typeClass;
        private List<String> allowedEnumValues;
        private Object value;
    }

}
