package com.jeequan.jeepay.db.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jeequan.jeepay.core.model.BaseModel;
import com.jeequan.jeepay.model.Condition;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 策略运行结果
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2024-05-09
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_route_record")
@NoArgsConstructor
public class RouteRecord extends BaseModel {

    private static final long serialVersionUID=1L;

    /**
     * 订单号
     */
    @TableId(type = IdType.INPUT)
    private String orderId;

    /**
     * 用户号
     */
    private String mchNo;

    /**
     * 路由ID
     */
    private String routeId;

    /**
     * 门店信息
     */
    private String storeId;

    /**
     * 商户号
     */
    private String applyId;

    /**
     * 执行目标对象
     */
    private String target;

    /**
     * 触发条件
     */
    @TableField(value = "`condition`")
    private String condition;

    /**
     * 执行结果
     */
    private String result;

    /**
     * 备注
     */
    private String remark;

    /**
     * 创建者用户ID
     */
    private Long createdUid;

    /**
     * 创建者姓名
     */
    private String createdBy;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;


    @TableField(exist = false)
    private String routeName;

    /**
     * 商户名称
     */
    @TableField(exist = false)
    private String mchShortName;

    /**
     * 门店名称
     */
    @TableField(exist = false)
    private String storeName;

    /**
     *
     * @param routeManage
     */
    public RouteRecord(RouteManage routeManage, List<Condition> conditionList) {
        this.mchNo = routeManage.getMchNo();
        this.routeId = routeManage.getRouteId();
        this.target = routeManage.getStoreName() + "["+routeManage.getStoreId()+"]";
        if(conditionList.isEmpty()){
            this.condition = "未触发规则";
            this.result = "";
        }else{
            this.condition = conditionList.get(0).getContentText();
            if(Condition.SEND_NOTIFY.equals(routeManage.getOpType()) && routeManage.getIsSend()){
                this.result = "发送门店通知";
            }else if (Condition.STORE_STATE.equals(routeManage.getOpType())){
                this.result = "更新门店状态";
            }else{
                this.result = "未知";
            }
        }
        this.remark = routeManage.getRemark();
    }
}
