package com.example.demo.model;

import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

/**
 * 失败任务清理日志实体
 * 用于记录被清理的失败任务信息
 */
@Entity
@Table(name = "failed_tasks_cleanup_log")
public class FailedTaskCleanupLog {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "task_id", nullable = false, length = 255)
    private String taskId;
    
    @Column(name = "username", nullable = false, length = 255)
    private String username;
    
    @Column(name = "task_type", nullable = false, length = 50)
    private String taskType;
    
    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;
    
    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt;
    
    @Column(name = "failed_at", nullable = false)
    private LocalDateTime failedAt;
    
    @Column(name = "cleaned_at")
    private LocalDateTime cleanedAt;
    
    // 构造函数
    public FailedTaskCleanupLog() {
        this.cleanedAt = LocalDateTime.now();
    }
    
    public FailedTaskCleanupLog(String taskId, String username, String taskType, 
                               String errorMessage, LocalDateTime createdAt, 
                               LocalDateTime failedAt) {
        this.taskId = taskId;
        this.username = username;
        this.taskType = taskType;
        this.errorMessage = errorMessage;
        this.createdAt = createdAt;
        this.failedAt = failedAt;
        this.cleanedAt = LocalDateTime.now();
    }
    
    // 从TextToVideoTask创建
    public static FailedTaskCleanupLog fromTextToVideoTask(TextToVideoTask task) {
        return new FailedTaskCleanupLog(
            task.getTaskId(),
            task.getUsername(),
            "TEXT_TO_VIDEO",
            task.getErrorMessage(),
            task.getCreatedAt(),
            task.getUpdatedAt()
        );
    }
    
    // 从ImageToVideoTask创建
    public static FailedTaskCleanupLog fromImageToVideoTask(ImageToVideoTask task) {
        return new FailedTaskCleanupLog(
            task.getTaskId(),
            task.getUsername(),
            "IMAGE_TO_VIDEO",
            task.getErrorMessage(),
            task.getCreatedAt(),
            task.getUpdatedAt()
        );
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getTaskId() {
        return taskId;
    }
    
    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getTaskType() {
        return taskType;
    }
    
    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }
    
    public String getErrorMessage() {
        return errorMessage;
    }
    
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getFailedAt() {
        return failedAt;
    }
    
    public void setFailedAt(LocalDateTime failedAt) {
        this.failedAt = failedAt;
    }
    
    public LocalDateTime getCleanedAt() {
        return cleanedAt;
    }
    
    public void setCleanedAt(LocalDateTime cleanedAt) {
        this.cleanedAt = cleanedAt;
    }
}
