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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * @Description :
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2020-08-10 15:13
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name="SYS_USER_CUSTOMIZE_CONFIG")
@ApiModel(value="用户定制化配置",description = "用户定制化配置")
public class SysUserCustomizeConfig extends BaseBean {

    private static final long serialVersionUID = -3757585990009089233L;

    @Column(name="USER_ID")
    @ApiModelProperty(value ="用户id" , example = "-1")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    @Column(name="CUSTOMIZE_CONFIG_TYPE")
    @ApiModelProperty(value ="定制化配置类型" , example = "-1")
    @AnnoOutputColumn(refClass = ImppEnumUtil.USER_CUSTOMIZE_CONFIG_TYPE.class)
    private Integer customizeConfigType;

    public String getCustomizeConfigTypeTxt() {
        return customizeConfigType == null ? "无" : ImppEnumUtil.USER_CUSTOMIZE_CONFIG_TYPE.valueOf(customizeConfigType);
    }

    @Column(name="CONFIG_KEY")
    @ApiModelProperty(value ="定制化配置类型" , example = "-1")
    private String configKey;

    @Column(name="CONFIG_VALUE")
    @ApiModelProperty(value ="配置值" , example = "-1")
    private String configValue;

    public String getRedisKey(String keyPrefix) {
        String redisKey = this.getUserId() + ":" + this.getCustomizeConfigType() + ":" + this.getConfigKey();
        if (StringUtils.isNotBlank(keyPrefix)) {
            return keyPrefix + ":" + redisKey;
        } else {
            return redisKey;
        }
    }

}
