import type { ServiceContract } from '../ServiceContract';

export const ISchedulerService: ServiceContract = {
  id: 'scheduler',
  description: 'Timer-based event scheduler for periodic and one-shot tasks',
  ops: {
    'scheduler.create': {
      description: 'Create a scheduled trigger',
      payload: {
        id: { type: 'string', required: false, description: 'Schedule ID (auto-generated if omitted)' },
        target: { type: 'string', required: true, description: 'Target actor mount' },
        op: { type: 'string', required: true, description: 'Operation to invoke' },
        payload: { type: 'object', required: false, description: 'Payload for the operation' },
        intervalMs: { type: 'number', required: false, description: 'Repeat interval (omit for one-shot)' },
        delayMs: { type: 'number', required: false, description: 'Initial delay' },
      },
      response: { ok: { type: 'boolean' }, id: { type: 'string' } },
    },
    'scheduler.cancel': {
      description: 'Cancel a scheduled trigger',
      payload: { id: { type: 'string', required: true } },
      response: { ok: { type: 'boolean' } },
    },
    'scheduler.list': {
      description: 'List all active schedules',
      payload: {},
      response: { ok: { type: 'boolean' }, schedules: { type: 'object[]' } },
    },
    'scheduler.get': {
      description: 'Get details of a specific schedule',
      payload: { id: { type: 'string', required: true } },
      response: { ok: { type: 'boolean' }, schedule: { type: 'object | null' } },
    },
    'scheduler.pause': {
      description: 'Pause a schedule',
      payload: { id: { type: 'string', required: true } },
      response: { ok: { type: 'boolean' } },
    },
    'scheduler.resume': {
      description: 'Resume a paused schedule',
      payload: { id: { type: 'string', required: true } },
      response: { ok: { type: 'boolean' } },
    },
  },
};
