package com.qqchen.deploy.backend.schedule.dto;

import com.qqchen.deploy.backend.framework.dto.BaseDTO;
import com.qqchen.deploy.backend.schedule.enums.ScheduleJobStatusEnum;
import com.qqchen.deploy.backend.workflow.dto.FormDefinitionDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 定时任务DTO
 * 
 * @author qichen
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "定时任务信息")
public class ScheduleJobDTO extends BaseDTO {

    @Schema(description = "任务名称", example = "工作流数据清理")
    @NotBlank(message = "任务名称不能为空")
    private String jobName;

    @Schema(description = "任务描述")
    private String jobDescription;

    @Schema(description = "任务分类ID")
    @NotNull(message = "任务分类ID不能为空")
    private Long categoryId;

    @Schema(description = "任务分类信息")
    private ScheduleJobCategoryDTO category;

    // ==================== 执行配置 ====================

    @Schema(description = "Spring Bean名称", example = "workflowCleanJob")
    @NotBlank(message = "Bean名称不能为空")
    private String beanName;

    @Schema(description = "方法名称", example = "execute")
    @NotBlank(message = "方法名称不能为空")
    private String methodName;

    @Schema(description = "参数表单ID")
    private Long formDefinitionId;

    @Schema(description = "参数表单信息")
    private FormDefinitionDTO formDefinition;

    @Schema(description = "方法参数JSON")
    private String methodParams;

    // ==================== 调度配置 ====================

    @Schema(description = "Cron表达式", example = "0 0 2 * * ?")
    @NotBlank(message = "Cron表达式不能为空")
    private String cronExpression;

    @Schema(description = "任务状态")
    @NotNull(message = "任务状态不能为空")
    private ScheduleJobStatusEnum status;

    @Schema(description = "是否允许并发执行")
    private Boolean concurrent;

    // ==================== 统计信息 ====================

    @Schema(description = "上次执行时间")
    private LocalDateTime lastExecuteTime;

    @Schema(description = "下次执行时间")
    private LocalDateTime nextExecuteTime;

    @Schema(description = "执行次数")
    private Integer executeCount;

    @Schema(description = "成功次数")
    private Integer successCount;

    @Schema(description = "失败次数")
    private Integer failCount;

    // ==================== 高级配置 ====================

    @Schema(description = "超时时间（秒）")
    private Integer timeoutSeconds;

    @Schema(description = "失败重试次数")
    private Integer retryCount;

    @Schema(description = "告警邮箱（多个用逗号分隔）")
    private String alertEmail;
}

