package com.example.demo.model;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * 成功任务归档实体
 * 用于存储已完成的任务信息
 */
@Entity
@Table(name = "completed_tasks_archive")
public class CompletedTaskArchive {
    
    @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 = "prompt", columnDefinition = "TEXT")
    private String prompt;
    
    @Column(name = "aspect_ratio", length = 20)
    private String aspectRatio;
    
    @Column(name = "duration")
    private Integer duration;
    
    @Column(name = "hd_mode")
    private Boolean hdMode = false;
    
    @Column(name = "result_url", columnDefinition = "TEXT")
    private String resultUrl;
    
    @Column(name = "real_task_id", length = 255)
    private String realTaskId;
    
    @Column(name = "progress")
    private Integer progress = 100;
    
    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt;
    
    @Column(name = "completed_at", nullable = false)
    private LocalDateTime completedAt;
    
    @Column(name = "archived_at")
    private LocalDateTime archivedAt;
    
    @Column(name = "points_cost")
    private Integer pointsCost = 0;
    
    // 构造函数
    public CompletedTaskArchive() {
        this.archivedAt = LocalDateTime.now();
    }
    
    public CompletedTaskArchive(String taskId, String username, String taskType, 
                               String prompt, String aspectRatio, Integer duration, 
                               Boolean hdMode, String resultUrl, String realTaskId, 
                               LocalDateTime createdAt, LocalDateTime completedAt, 
                               Integer pointsCost) {
        this.taskId = taskId;
        this.username = username;
        this.taskType = taskType;
        this.prompt = prompt;
        this.aspectRatio = aspectRatio;
        this.duration = duration;
        this.hdMode = hdMode;
        this.resultUrl = resultUrl;
        this.realTaskId = realTaskId;
        this.createdAt = createdAt;
        this.completedAt = completedAt;
        this.archivedAt = LocalDateTime.now();
        this.pointsCost = pointsCost;
        this.progress = 100;
    }
    
    // 从TextToVideoTask创建
    public static CompletedTaskArchive fromTextToVideoTask(TextToVideoTask task) {
        return new CompletedTaskArchive(
            task.getTaskId(),
            task.getUsername(),
            "TEXT_TO_VIDEO",
            task.getPrompt(),
            task.getAspectRatio(),
            task.getDuration(),
            task.isHdMode(),
            task.getResultUrl(),
            task.getRealTaskId(),
            task.getCreatedAt(),
            task.getUpdatedAt(),
            10 // 默认积分消耗
        );
    }
    
    // 从ImageToVideoTask创建
    public static CompletedTaskArchive fromImageToVideoTask(ImageToVideoTask task) {
        return new CompletedTaskArchive(
            task.getTaskId(),
            task.getUsername(),
            "IMAGE_TO_VIDEO",
            task.getPrompt(),
            task.getAspectRatio(),
            task.getDuration(),
            task.getHdMode(),
            task.getResultUrl(),
            task.getRealTaskId(),
            task.getCreatedAt(),
            task.getUpdatedAt(),
            15 // 默认积分消耗
        );
    }
    
    // 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 getPrompt() {
        return prompt;
    }
    
    public void setPrompt(String prompt) {
        this.prompt = prompt;
    }
    
    public String getAspectRatio() {
        return aspectRatio;
    }
    
    public void setAspectRatio(String aspectRatio) {
        this.aspectRatio = aspectRatio;
    }
    
    public Integer getDuration() {
        return duration;
    }
    
    public void setDuration(Integer duration) {
        this.duration = duration;
    }
    
    public Boolean getHdMode() {
        return hdMode;
    }
    
    public void setHdMode(Boolean hdMode) {
        this.hdMode = hdMode;
    }
    
    public String getResultUrl() {
        return resultUrl;
    }
    
    public void setResultUrl(String resultUrl) {
        this.resultUrl = resultUrl;
    }
    
    public String getRealTaskId() {
        return realTaskId;
    }
    
    public void setRealTaskId(String realTaskId) {
        this.realTaskId = realTaskId;
    }
    
    public Integer getProgress() {
        return progress;
    }
    
    public void setProgress(Integer progress) {
        this.progress = progress;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getCompletedAt() {
        return completedAt;
    }
    
    public void setCompletedAt(LocalDateTime completedAt) {
        this.completedAt = completedAt;
    }
    
    public LocalDateTime getArchivedAt() {
        return archivedAt;
    }
    
    public void setArchivedAt(LocalDateTime archivedAt) {
        this.archivedAt = archivedAt;
    }
    
    public Integer getPointsCost() {
        return pointsCost;
    }
    
    public void setPointsCost(Integer pointsCost) {
        this.pointsCost = pointsCost;
    }
}
