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

import com.qqchen.deploy.backend.framework.annotation.LogicDelete;
import com.qqchen.deploy.backend.framework.domain.Entity;
import jakarta.persistence.Column;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * SSH终端审计日志实体
 * 
 * ⚠️ 审计日志逻辑删除设计：
 * - 支持逻辑删除（@LogicDelete）而非物理删除
 * - 确保审计记录的可追溯性和合规性
 * - 删除的审计日志仍可通过后台管理查询
 */
@Data
@EqualsAndHashCode(callSuper = true)
@jakarta.persistence.Entity
@Table(name = "deploy_ssh_audit_log")
@LogicDelete
public class SSHAuditLog extends Entity<Long> {

    /**
     * 用户ID
     */
    @Column(name = "user_id", nullable = false)
    private Long userId;

    /**
     * 用户名（冗余）
     */
    @Column(name = "username", length = 50)
    private String username;

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

    /**
     * 服务器名称（冗余）
     */
    @Column(name = "server_name", length = 100)
    private String serverName;

    /**
     * 服务器IP（冗余）
     */
    @Column(name = "server_ip", length = 50)
    private String serverIp;

    /**
     * WebSocket会话ID
     */
    @Column(name = "session_id", nullable = false, length = 100)
    private String sessionId;

    /**
     * 连接时间
     */
    @Column(name = "connect_time", nullable = false)
    private LocalDateTime connectTime;

    /**
     * 断开时间
     */
    @Column(name = "disconnect_time")
    private LocalDateTime disconnectTime;

    /**
     * 会话时长（秒）
     */
    @Column(name = "duration_seconds")
    private Integer durationSeconds;

    /**
     * 客户端IP
     */
    @Column(name = "client_ip", length = 50)
    private String clientIp;

    /**
     * 浏览器UA
     */
    @Column(name = "user_agent", length = 500)
    private String userAgent;

    /**
     * 执行命令数量
     */
    @Column(name = "command_count", nullable = false)
    private Integer commandCount = 0;

    /**
     * 执行的命令记录（JSON数组）
     */
    @Column(name = "commands", columnDefinition = "LONGTEXT")
    private String commands;

    /**
     * 状态：SUCCESS成功, FAILED失败, TIMEOUT超时, INTERRUPTED中断
     */
    @Column(name = "status", length = 20)
    private String status;

    /**
     * 错误信息
     */
    @Column(name = "error_message", length = 500)
    private String errorMessage;
}
