import type { BaseResponse, BaseRequest, BaseQuery } from '@/types/base';

/**
 * 定时任务分类响应
 */
export interface JobCategoryResponse extends BaseResponse {
    code: string;
    name: string;
    description?: string;
    icon?: string;
    color?: string;
    sort?: number;
}

/**
 * 定时任务分类请求
 */
export interface JobCategoryRequest extends BaseRequest {
    code: string;
    name: string;
    description?: string;
    icon?: string;
    color?: string;
    enabled?: boolean;
    sort?: number;
}

/**
 * 定时任务分类查询
 */
export interface JobCategoryQuery extends BaseQuery {
    name?: string;
    enabled?: boolean;
}

/**
 * 定时任务状态
 */
export type JobStatus = 'ENABLED' | 'DISABLED' | 'PAUSED';

/**
 * 定时任务响应
 */
export interface ScheduleJobResponse extends BaseResponse {
    jobName: string;
    jobDescription?: string;
    categoryId: number;
    category?: JobCategoryResponse;
    
    // 执行配置
    beanName: string;
    methodName: string;
    formDefinitionId?: number;
    methodParams?: string;
    
    // 调度配置
    cronExpression: string;
    status: JobStatus;
    concurrent?: boolean;
    
    // 统计信息
    lastExecuteTime?: string;
    nextExecuteTime?: string;
    executeCount?: number;
    successCount?: number;
    failCount?: number;
    
    // 高级配置
    timeoutSeconds?: number;
    retryCount?: number;
    alertEmail?: string;
}

/**
 * 定时任务请求
 */
export interface ScheduleJobRequest extends BaseRequest {
    jobName: string;
    jobDescription?: string;
    categoryId: number;
    
    // 执行配置
    beanName: string;
    methodName: string;
    formDefinitionId?: number;
    methodParams?: string;
    
    // 调度配置
    cronExpression: string;
    status: JobStatus;
    concurrent?: boolean;
    
    // 高级配置
    timeoutSeconds?: number;
    retryCount?: number;
    alertEmail?: string;
}

/**
 * 定时任务查询
 */
export interface ScheduleJobQuery extends BaseQuery {
    jobName?: string;
    categoryId?: number;
    status?: JobStatus;
}

/**
 * 执行日志状态
 */
export type LogStatus = 'SUCCESS' | 'FAIL' | 'TIMEOUT';

/**
 * 定时任务执行日志响应
 */
export interface ScheduleJobLogResponse extends BaseResponse {
    jobId: number;
    jobName: string;
    
    // 执行信息
    beanName: string;
    methodName: string;
    methodParams?: string;
    
    // 时间统计
    executeTime: string;
    finishTime?: string;
    duration?: number;
    
    // 状态信息
    status: LogStatus;
    resultMessage?: string;
    exceptionInfo?: string;
    
    // 服务器信息
    serverIp?: string;
    serverHost?: string;
}

/**
 * 定时任务执行日志查询
 */
export interface ScheduleJobLogQuery extends BaseQuery {
    jobId?: number;
    jobName?: string;
    status?: LogStatus;
    executeTimeStart?: string;
    executeTimeEnd?: string;
}

/**
 * 仪表盘概览统计
 */
export interface DashboardSummary {
    total: number;
    enabled: number;
    disabled: number;
    paused: number;
    running: number;
}

/**
 * 正在运行的任务
 */
export interface RunningJob {
    jobId: number;
    jobName: string;
    startTime: string;
    progress: number;
    message?: string;
    status: string;
}

/**
 * 仪表盘响应
 */
export interface DashboardResponse {
    summary: DashboardSummary;
    runningJobs: RunningJob[];
    recentLogs: ScheduleJobLogResponse[];
}

