package com.muyu.rule.common.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.rule.common.domain.req.EtlRuleAddReq;
import com.muyu.rule.common.domain.req.EtlRuleUpdReq;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.function.Supplier;

/**
 * @Author：张承志
 * @Package：com.muyu.damain
 * @Project：cloud-etl
 * @name：Rule
 * @Date：2024/8/21 11:33
 */

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "rule_engine",autoResultMap = true)
public class RuleEngine extends BaseEntity {

    /**
     *主键
     */
    @TableId(value = "id" , type = IdType.AUTO)
    private Long id ;
    /** 规则名称 */

    private String name ;
    /** 规则类型 */


    /** 引擎编码  */
    private String code;



    /** 规则作用域 */
    private String regionName;



    /** 是否公开 0已激活 1未激活 */
    private String open;


    /** 状态 0正常 1停用 */
    private String status ;


    /** 规则引擎描述 */
    private String ruleDesc;

    public static RuleEngine updBuild(EtlRuleUpdReq etlRule, Supplier<Long> longSupplier){

      return RuleEngine.builder().id(longSupplier.get())
                 .open(etlRule.getOpen())
                 .name(etlRule.getName())
                 .regionName(etlRule.getRegionName())
                 .status(etlRule.getStatus())
                 .code(etlRule.getCode())
                 .remark(etlRule.getRemark())
              .ruleDesc(etlRule.getRuleDesc())
                 .build();

    }

    public static RuleEngine addBuild(EtlRuleAddReq etlRule){

        return RuleEngine.builder()
                .open(etlRule.getOpen())
                .name(etlRule.getName())
                .regionName(etlRule.getRegionName())
                .status(etlRule.getStatus())
                .code(etlRule.getCode())
                .ruleDesc(etlRule.getRuleDesc())
                .remark(etlRule.getRemark())
                .build();

    }
}
