// Auto-Run Recurring Task System

export interface RecurringTemplate {
  id: string;
  name: string;
  description: string;
  agent: string; // thoth, ptah, seshat, anubis, etc.
  project: string;
  schedule: {
    type: 'hourly' | 'daily' | 'weekly' | 'monthly';
    time?: string; // HH:MM format for daily
    dayOfWeek?: number; // 0-6 for weekly
    dayOfMonth?: number; // 1-31 for monthly
    timezone: string; // Europe/Madrid
  };
  taskTemplate: {
    title: string;
    description: string;
    priority: 'critical' | 'high' | 'medium' | 'low';
  };
  preInstructions?: string;
  enabled: boolean;
  lastRun?: string;
  nextRun?: string;
  runCount: number;
}

export interface ExecutionLog {
  id: string;
  templateId: string;
  agent: string;
  taskTitle: string;
  startedAt: string;
  completedAt?: string;
  status: 'running' | 'completed' | 'failed' | 'cancelled';
  output?: string;
  error?: string;
}

export interface ChangeLogEntry {
  id: string;
  date: string;
  agent: string;
  type: 'skill_update' | 'template_change' | 'new_feature' | 'bug_fix';
  description: string;
  version?: string;
}

// Predefined SiteMente Agent Tasks
export const defaultRecurringTemplates: RecurringTemplate[] = [
  // Thoth - Daily Research
  {
    id: 'thoth-daily-research',
    name: 'Thoth - Daily SiteMente Research',
    description: 'Research market trends, competitors, and opportunities',
    agent: 'thoth',
    project: 'sitemente',
    schedule: { type: 'daily', time: '09:00', timezone: 'Europe/Madrid' },
    taskTemplate: {
      title: 'Daily SiteMente Research',
      description: 'Research: competitors, AI trends, pricing, local businesses',
      priority: 'high'
    },
    preInstructions: 'Focus on: 1) Competitor changes, 2) New AI features, 3) Local lead opportunities',
    enabled: false,
    runCount: 0
  },
  // Ptah - Infra Monitoring
  {
    id: 'ptah-infra-monitor',
    name: 'Ptah - Infrastructure Monitoring',
    description: 'Check server health, uptime, and security',
    agent: 'ptah',
    project: 'infrastructure',
    schedule: { type: 'hourly', timezone: 'Europe/Madrid' },
    taskTemplate: {
      title: 'Infra Health Check',
      description: 'Check: CPU, memory, disk, services, SSL certs, security logs',
      priority: 'critical'
    },
    preInstructions: 'Report any issues immediately to Horus',
    enabled: false,
    runCount: 0
  },
  // Seshat - Content Pipeline
  {
    id: 'seshat-content-pipeline',
    name: 'Seshat - Content Pipeline',
    description: 'Generate and schedule content',
    agent: 'seshat',
    project: 'sitemente',
    schedule: { type: 'daily', time: '09:00', timezone: 'Europe/Madrid' },
    taskTemplate: {
      title: 'Daily Content Development',
      description: 'Create: blog post, social content, newsletter draft',
      priority: 'medium'
    },
    preInstructions: 'Focus on SEO, value for local businesses',
    enabled: false,
    runCount: 0
  },
  // Anubis - Outreach Scan
  {
    id: 'anubis-outreach-scan',
    name: 'Anubis - Outreach Opportunities',
    description: 'Find new leads and opportunities',
    agent: 'anubis',
    project: 'sitemente',
    schedule: { type: 'weekly', dayOfWeek: 1, time: '10:00', timezone: 'Europe/Madrid' },
    taskTemplate: {
      title: 'Weekly Outreach Scan',
      description: 'Find: new restaurants, clinics, real estate agencies to contact',
      priority: 'high'
    },
    preInstructions: 'Focus on Benalmádena and Costa del Sol area',
    enabled: false,
    runCount: 0
  },
  // Thoth Trading - Market Scan
  {
    id: 'thoth-trading-market',
    name: 'Thoth Trading - Market Scan',
    description: 'Scan crypto markets for opportunities',
    agent: 'thoth-trading',
    project: 'trading',
    schedule: { type: 'hourly', timezone: 'Europe/Madrid' },
    taskTemplate: {
      title: 'Market Scan',
      description: 'Check: BTC, ETH, SOL prices and trends',
      priority: 'medium'
    },
    preInstructions: 'Report significant moves (>5%)',
    enabled: false,
    runCount: 0
  },
  // Sekhmet - Risk Alerts
  {
    id: 'sekhmet-risk-alerts',
    name: 'Sekhmet - Risk Alerts',
    description: 'Monitor trading positions and risk',
    agent: 'sekhmet',
    project: 'trading',
    schedule: { type: 'hourly', timezone: 'Europe/Madrid' },
    taskTemplate: {
      title: 'Risk Check',
      description: 'Check: open positions, drawdown, risk levels',
      priority: 'high'
    },
    preInstructions: 'Alert if drawdown >10% or positions at risk',
    enabled: false,
    runCount: 0
  }
];
