package com.common.entity;

import lombok.Data;
import java.time.LocalDateTime;

/**
 * 探针心跳历史记录实体类
 * 对应表: device_collect_heartbeat_history
 */
@Data
public class DeviceCollectHeartbeatHistory {
    
    /** 自增主键 */
    private Long id;
    
    /** 探针唯一标识 */
    private String collectId;
    
    /** 心跳上报时间 */
    private LocalDateTime heartbeatTime;
    
    /** 探针IP */
    private String deviceIp;
    
    /** 探针版本 */
    private String appVersion;
    
    /** 记录创建时间 */
    private LocalDateTime createdAt;

    
    public DeviceCollectHeartbeatHistory() {
        this.createdAt = LocalDateTime.now();
    }
    
    /**
     * 从心跳状态创建历史记录
     */
    public static DeviceCollectHeartbeatHistory fromHeartbeat(DeviceCollectHeartbeat heartbeat) {
        DeviceCollectHeartbeatHistory history = new DeviceCollectHeartbeatHistory();
        history.setCollectId(heartbeat.getCollectId());
        history.setHeartbeatTime(heartbeat.getLastHeartbeat());
        history.setDeviceIp(heartbeat.getDeviceIp());
        history.setAppVersion(heartbeat.getAppVersion());
        history.setCreatedAt(LocalDateTime.now());
        return history;
    }
}
