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.CommonEnumUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @Description : 系统资源表，通过resourceType，languageId和resourceKey三者，查询value
 * 查询顺序：resourceType-》languageId-》resourceKey
 * 如果通过languageId无法获取资源，则通过resourceType和resourceKey查询default默认资源
 * @Reference :
 * @Author : alwaysfrin
 * @CreateDate : 2018-10-11 11:01
 * @Modify:
 **/
@Entity
@Data
@EqualsAndHashCode(callSuper = true)
@Table(name="sys_locale_resource")
@Api(value="系统资源",description = "对按钮、功能、信息提示等进行转换。")
public class SysLocaleResource  extends BaseBean {

    private static final long serialVersionUID = -2397207310100672746L;

    @Column(name="resource_type")
    @AnnoOutputColumn(refClass = CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.class, refForeignKey = "value", value = "description")
    @ApiParam(value = "资源类型",example = "1",access = "使用枚举：CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE")
    private Integer resourceType;

    @Transient
    private String resourceTypeTxt;

    public String getResourceTypeTxt(){
        if(this.resourceType != null){
            return CommonEnumUtil.SYS_LOCALE_RESOURCE_TYPE.valueOf(this.resourceType);
        } else {
            return null;
        }
    }

    @Column(name="language_code")
    @ApiParam(value = "语言编码",example = "浏览器语言编码")
    @AnnoOutputColumn
    private String languageCode;

    @Column(name="language_name_rdd")
    @ApiParam(value = "语言名称",example = "浏览器语言名称")
    private String languageNameRdd;

    @Lob
    @Column(name="resource_key")
    @ApiParam(value = "资源KEY",example = "格式A.B，全部大写，参考命名规范开发文档")
    @AnnoOutputColumn
    private String resourceKey;

    @Lob
    @Column(name="resource_value")
    @ApiParam(value = "资源Value",example = "通过resourceType，languageId和key获取")
    private String resourceValue;

    @Column(name="SOFT_TYPE")
    @ApiParam(value ="产品类型", example = "0",access = "softTyp DOC: http://doc.estsh.com/docs/i3plus_api/i3plus_api-impp")
    @AnnoOutputColumn(refClass = CommonEnumUtil.SOFT_TYPE.class, refForeignKey = "value", value = "description",required = false)
    private Integer softType;
    public int getSoftTypeVal(){
        if(softType==null){
            return CommonEnumUtil.SOFT_TYPE.IMPP.getValue();
        }
        return softType.intValue();
    }

    //系统自带需要有初始化表，只能修改value，无法删除。
    @Column(name="is_system")
    @ApiParam(value = "是否系统参数",example = "2")
    @AnnoOutputColumn(refClass = CommonEnumUtil.TRUE_OR_FALSE.class, refForeignKey = "value", value = "description")
    private Integer isSystem;

    /**
     * 检索条件
     */
    @Transient
    private String resourceTypes;

}
