package com.qqchen.deploy.backend.deploy.entity;

import com.qqchen.deploy.backend.framework.enums.StatusEnum;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 服务器监控记录实体
 * 注意：监控记录不需要审计字段和软删除，使用简单实体
 */
@Data
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@lombok.Builder
@Entity
@Table(name = "deploy_server_monitor")
public class ServerMonitor {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 服务器ID
     */
    @Column(name = "server_id", nullable = false)
    private Long serverId;

    /**
     * CPU使用率(%)
     */
    @Column(name = "cpu_usage", precision = 5, scale = 2)
    private BigDecimal cpuUsage;

    /**
     * 内存使用率(%)
     */
    @Column(name = "memory_usage", precision = 5, scale = 2)
    private BigDecimal memoryUsage;

    /**
     * 已用内存(GB)
     */
    @Column(name = "memory_used")
    private Integer memoryUsed;

    /**
     * 磁盘使用情况（JSON格式）
     */
    @Column(name = "disk_usage", columnDefinition = "JSON")
    private String diskUsage;

    /**
     * 网络接收(KB/s)
     */
    @Column(name = "network_rx")
    private Long networkRx;

    /**
     * 网络发送(KB/s)
     */
    @Column(name = "network_tx")
    private Long networkTx;

    /**
     * 采集时间
     */
    @Column(name = "collect_time", nullable = false)
    private LocalDateTime collectTime;

    /**
     * 采集状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private StatusEnum status = StatusEnum.SUCCESS;
}
