import { z } from 'zod';
import type { ToolDef } from '../tool-registry.js';

const CampaignStatus = z.enum(['DRAFT', 'ACTIVE', 'PAUSED', 'CLOSED']);
const GovernmentLevel = z.enum(['FEDERAL', 'PROVINCIAL', 'MUNICIPAL', 'SCHOOL_BOARD']);

export const campaignTools: ToolDef[] = [
  {
    name: 'campaigns_list',
    description:
      'List advocacy campaigns. Filter by status (DRAFT, ACTIVE, PAUSED, CLOSED) ' +
      'or search by title. Returns paginated results with email/response counts.',
    inputSchema: {
      page: z.coerce.number().int().positive().default(1).describe('Page number'),
      limit: z.coerce.number().int().positive().max(100).default(20).describe('Items per page'),
      search: z.string().optional().describe('Search campaigns by title'),
      status: CampaignStatus.optional().describe('Filter by campaign status'),
    },
    method: 'GET',
    path: '/api/campaigns',
    tier: 1,
  },
  {
    name: 'campaigns_get',
    description:
      'Get full details of a single campaign by ID, including title, email template, ' +
      'status, target government levels, and feature flags.',
    inputSchema: {
      id: z.string().describe('Campaign ID'),
    },
    method: 'GET',
    path: '/api/campaigns/:id',
    tier: 1,
  },
  {
    name: 'campaigns_create',
    description:
      'Create a new advocacy campaign. Requires title, emailSubject, and emailBody. ' +
      'The campaign starts in DRAFT status by default. Set targetGovernmentLevels ' +
      'to specify which representatives constituents can email.',
    inputSchema: {
      title: z.string().min(1).max(200).describe('Campaign title'),
      description: z.string().max(2000).optional().describe('Campaign description'),
      emailSubject: z.string().min(1).max(200).describe('Email subject line for advocacy emails'),
      emailBody: z.string().min(1).max(10000).describe('Email body template for advocacy emails'),
      callToAction: z.string().max(500).optional().describe('Call to action text'),
      status: CampaignStatus.optional().default('DRAFT').describe('Campaign status'),
      targetGovernmentLevels: z.array(GovernmentLevel).optional().default([]).describe('Government levels to target'),
      allowSmtpEmail: z.boolean().optional().default(true).describe('Allow server-side SMTP email sending'),
      allowMailtoLink: z.boolean().optional().default(true).describe('Allow mailto: link fallback'),
      collectUserInfo: z.boolean().optional().default(true).describe('Collect sender info'),
      showEmailCount: z.boolean().optional().default(true).describe('Show email count publicly'),
      showResponseWall: z.boolean().optional().default(false).describe('Enable response wall'),
      highlightCampaign: z.boolean().optional().default(false).describe('Highlight on campaigns list'),
    },
    method: 'POST',
    path: '/api/campaigns',
    tier: 1,
  },
  {
    name: 'campaigns_update',
    description:
      'Update an existing campaign. Only provided fields are changed. ' +
      'Use this to change status (e.g., DRAFT → ACTIVE to publish), update email templates, etc.',
    inputSchema: {
      id: z.string().describe('Campaign ID'),
      title: z.string().min(1).max(200).optional().describe('Campaign title'),
      description: z.string().max(2000).nullable().optional().describe('Campaign description'),
      emailSubject: z.string().min(1).max(200).optional().describe('Email subject line'),
      emailBody: z.string().min(1).max(10000).optional().describe('Email body template'),
      status: CampaignStatus.optional().describe('Campaign status'),
      targetGovernmentLevels: z.array(GovernmentLevel).optional().describe('Government levels to target'),
    },
    method: 'PUT',
    path: '/api/campaigns/:id',
    tier: 1,
  },
  {
    name: 'campaigns_delete',
    description: 'Delete a campaign by ID. This is permanent and cannot be undone.',
    inputSchema: {
      id: z.string().describe('Campaign ID'),
    },
    method: 'DELETE',
    path: '/api/campaigns/:id',
    tier: 1,
  },
];
