package com.gameplatform.server.model.entity.detection;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDateTime;

/**
 * 游戏完成检测日志实体
 */
@TableName("game_completion_log")
public class GameCompletionLog {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    /**
     * 链接任务ID
     */
    private Long linkTaskId;
    
    /**
     * 设备ID
     */
    private String machineId;
    
    /**
     * 检测来源：TIMER_TASK-定时任务, EVENT_LISTENER-事件监听, REGION_SELECT-选区检查, MANUAL-手动
     */
    private String detectionSource;
    
    /**
     * 设备状态
     */
    private String deviceStatus;
    
    /**
     * 检测到的点数
     */
    private Integer pointsDetected;
    
    /**
     * 完成置信度：HIGH-高, MEDIUM-中, LOW-低
     */
    private String completionConfidence;
    
    /**
     * 是否已确认完成
     */
    private Boolean isConfirmed;
    
    /**
     * 确认完成时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime confirmationTime;
    
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;
    
    // 构造函数
    public GameCompletionLog() {}
    
    public GameCompletionLog(Long linkTaskId, String machineId, String detectionSource, 
                           String deviceStatus, Integer pointsDetected, String completionConfidence) {
        this.linkTaskId = linkTaskId;
        this.machineId = machineId;
        this.detectionSource = detectionSource;
        this.deviceStatus = deviceStatus;
        this.pointsDetected = pointsDetected;
        this.completionConfidence = completionConfidence;
        this.isConfirmed = false;
        this.createdAt = LocalDateTime.now();
    }
    
    // Getter and Setter methods
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getLinkTaskId() {
        return linkTaskId;
    }
    
    public void setLinkTaskId(Long linkTaskId) {
        this.linkTaskId = linkTaskId;
    }
    
    public String getMachineId() {
        return machineId;
    }
    
    public void setMachineId(String machineId) {
        this.machineId = machineId;
    }
    
    public String getDetectionSource() {
        return detectionSource;
    }
    
    public void setDetectionSource(String detectionSource) {
        this.detectionSource = detectionSource;
    }
    
    public String getDeviceStatus() {
        return deviceStatus;
    }
    
    public void setDeviceStatus(String deviceStatus) {
        this.deviceStatus = deviceStatus;
    }
    
    public Integer getPointsDetected() {
        return pointsDetected;
    }
    
    public void setPointsDetected(Integer pointsDetected) {
        this.pointsDetected = pointsDetected;
    }
    
    public String getCompletionConfidence() {
        return completionConfidence;
    }
    
    public void setCompletionConfidence(String completionConfidence) {
        this.completionConfidence = completionConfidence;
    }
    
    public Boolean getIsConfirmed() {
        return isConfirmed;
    }
    
    public void setIsConfirmed(Boolean isConfirmed) {
        this.isConfirmed = isConfirmed;
    }
    
    public LocalDateTime getConfirmationTime() {
        return confirmationTime;
    }
    
    public void setConfirmationTime(LocalDateTime confirmationTime) {
        this.confirmationTime = confirmationTime;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    /**
     * 确认完成
     */
    public void confirm() {
        this.isConfirmed = true;
        this.confirmationTime = LocalDateTime.now();
    }
    
    /**
     * 是否为高置信度检测
     */
    public boolean isHighConfidence() {
        return "HIGH".equals(completionConfidence);
    }
    
    /**
     * 是否为可靠的检测来源
     */
    public boolean isReliableSource() {
        return "MANUAL".equals(detectionSource) || "REGION_SELECT".equals(detectionSource);
    }
    
    @Override
    public String toString() {
        return "GameCompletionLog{" +
                "id=" + id +
                ", linkTaskId=" + linkTaskId +
                ", machineId='" + machineId + '\'' +
                ", detectionSource='" + detectionSource + '\'' +
                ", deviceStatus='" + deviceStatus + '\'' +
                ", pointsDetected=" + pointsDetected +
                ", completionConfidence='" + completionConfidence + '\'' +
                ", isConfirmed=" + isConfirmed +
                ", confirmationTime=" + confirmationTime +
                ", createdAt=" + createdAt +
                '}';
    }
}

