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

import cn.estsh.i3plus.pojo.aps.annotation.ExcludeImportExport;
import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.ERuleDetail;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
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.Table;

/**
 * @Description :规则组合下的规则明细
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-11-05
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_RULE_DETAIL")
@Api("规则明细")
@ExcludeImportExport
public class RuleDetail extends BaseAPS {

    private static final long serialVersionUID = -6433950357039396107L;
    @Column(name="TYPE")
    @ApiParam(value ="规则类型")
    private ApsEnumUtil.RULE_TYPE type;

    @Column(name="ORDER_NUMBER")
    @ApiParam(value ="序号")
    private Integer orderNumber;

    @Column(name="RULE_GROUP_ID")
    @ApiParam(value ="规则组合ID")
    @FieldAnnotation(relation = "RuleGroup", display = false)
    private Long ruleGroupId;

    @Column(name="RULE_ID")
    @ApiParam(value ="规则配置ID")
    @FieldAnnotation(relation = "Rule", display = false)
    private Long ruleId;

    public RuleGroup getRuleGroup() { return BeanRelation.get(this, ERuleDetail.RuleGroup); }

    public void setRuleGroup(RuleGroup ruleGroup) {
        this.ruleGroupId = ruleGroup != null ? ruleGroup.getId() : 0;
        BeanRelation.set(this, ERuleDetail.RuleGroup, ruleGroup);
    }

    public BaseRule getRule() { return BeanRelation.get(this, ERuleDetail.Rule); }

    public void setRule(BaseRule rule) {
        this.ruleId = rule != null ? rule.getId() : 0;
        BeanRelation.set(this, ERuleDetail.Rule, rule);
    }
}
