package com.muyu.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.domain.req.MessageValueAddReq;
import com.muyu.domain.resp.MessageValueListResp;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * 报文数据
 *  * @ClassName MessageValue
 *  * @Description TODO
 *  * @Author Li HD
 *  * @Date 2024/9/19
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "message_value", autoResultMap = true)
@Tag(name = "报文数据")
public class MessageValue extends BaseEntity {

    /**
     * 报文数据主键
     */
    @TableId(value = "message_id", type = IdType.AUTO)
    @Schema(title = "报文数据主键")
    private Long messageId;

    /**
     * 模版主键
     */
    @Schema(name = "模版主键")
    private Long templateId;

    /**
     * 报文类别
     */
    @Schema(name = "报文类别")
    private String messageType;

    /**
     * 报文编码
     */
    @Schema(name = "报文编码")
    private String messageCode;

    /**
     * 报文标签
     */
    @Schema(name = "报文标签")
    private String messageLabel;

    /**
     * 起始下标
     */
    @Schema(name = "起始下标")
    private Integer messageStartIndex;

    /**
     * 终止下标
     */
    @Schema(name = "终止下标")
    private Integer messageEndIndex;

    public static MessageValue addBuild(MessageValueAddReq messageValueAddReq){
        return MessageValue.builder()
                .templateId(messageValueAddReq.getTemplateId())
                .messageType(messageValueAddReq.getMessageType())
                .messageCode(messageValueAddReq.getMessageCode())
                .messageLabel(messageValueAddReq.getMessageLabel())
                .messageStartIndex(messageValueAddReq.getMessageStartIndex())
                .messageEndIndex(messageValueAddReq.getMessageEndIndex())
                .build();
    }
    public static MessageValue addRollback(MessageValueListResp messageValueListResp){
        return MessageValue.builder()
                .templateId(messageValueListResp.getMessageId())
                .messageType(messageValueListResp.getMessageType())
                .messageCode(messageValueListResp.getMessageCode())
                .messageLabel(messageValueListResp.getMessageLabel())
                .messageStartIndex(messageValueListResp.getMessageStartIndex())
                .messageEndIndex(messageValueListResp.getMessageEndIndex())
                .build();
    }
}
