import type { CamelizeKeys, DbRow } from "@riverbankcms/db";
/**
 * Communications Contracts
 *
 * These types cover email-template configuration and newsletter management
 * payloads that flow through the API package.
 *
 * Note: Do NOT use these API types as validation schemas. They document wire
 * contracts while the owning dashboard services validate and normalize inputs.
 */
export type EmailTemplateType = "event_confirmation" | "event_reminder" | "event_feedback_request" | "event_cancellation" | "event_cancellation_customer" | "event_cancellation_admin" | "event_refund_customer" | "event_refund_admin" | "event_transfer_customer" | "event_transfer_admin" | "pass_purchase_confirmation" | "membership_purchase_confirmation" | "membership_cancel_at_period_end" | "membership_payment_refund" | "appointment_confirmation" | "appointment_follow_up" | "appointment_reminder" | "appointment_follow_up" | "pass_refund" | "course_enrollment_confirmation" | "event_update" | "event_cancelled_by_organizer" | "digital_product_fulfillment" | "order_confirmation" | "order_shipment" | "order_cancellation" | "order_payment_reminder_customer" | "order_balance_due_customer" | "order_balance_overdue_customer" | "order_balance_overdue_admin" | "form_submitter_auto_reply";
export type EmailTemplate = {
    id: string;
    siteId: string;
    templateType: EmailTemplateType;
    subjectTemplate: string | null;
    bodyTemplate: string | null;
    createdAt: string;
    updatedAt: string;
};
export type EmailTemplateInput = {
    subjectTemplate?: string | null;
    bodyTemplate?: string | null;
};
export type EventEmailTemplateType = "event_confirmation" | "event_reminder";
export type EventEmailTemplate = {
    id: string;
    siteId: string;
    eventSeriesId: string;
    templateType: EventEmailTemplateType;
    subjectTemplate: string | null;
    bodyTemplate: string | null;
    createdAt: string;
    updatedAt: string;
};
export type GetEventSeriesEmailTemplatesResponse = {
    templates: Partial<Record<EventEmailTemplateType, EventEmailTemplate>>;
    availableTypes: EventEmailTemplateType[];
};
export type UpdateEventSeriesEmailTemplatesRequest = {
    templates?: Partial<Record<EventEmailTemplateType, EmailTemplateInput | null>>;
};
export type UpdateEventSeriesEmailTemplatesResponse = {
    templates: Partial<Record<EventEmailTemplateType, EventEmailTemplate>>;
};
export type GlobalEmailSettings = {
    fromName: string | null;
    replyToEmail: string | null;
    fromEmail: string | null;
};
export type GlobalEmailSettingsInput = {
    fromName?: string;
    replyToEmail?: string;
    fromEmail?: string;
};
export type GetEmailSettingsResponse = {
    templates: Partial<Record<EmailTemplateType, EmailTemplate>>;
    globalSettings: GlobalEmailSettings | null;
    availableTypes: EmailTemplateType[];
    availableVariables: string[];
};
export type UpdateEmailSettingsRequest = {
    templates?: Partial<Record<EmailTemplateType, EmailTemplateInput>>;
    globalSettings?: GlobalEmailSettingsInput;
};
export type UpdateEmailSettingsResponse = {
    templates: Partial<Record<EmailTemplateType, EmailTemplate>>;
    globalSettings: GlobalEmailSettings | null;
    updated: string[];
    globalSettingsUpdated?: boolean;
};
export type SendTestEmailRequest = {
    templateType: EmailTemplateType;
    formData: {
        subjectTemplate?: string | null;
        bodyTemplate?: string | null;
    };
};
export type SendTestEmailResponse = {
    sent: boolean;
    email: string;
};
export type PreviewEmailTemplateRequest = {
    templateType: EmailTemplateType;
    formData: {
        subjectTemplate?: string | null;
        bodyTemplate?: string | null;
    };
};
export type PreviewEmailTemplateResponse = {
    subject: string;
    bodyHtml: string;
    bodyText: string;
    fromName: string | null;
    replyToEmail: string | null;
};
export type NewsletterSettingsRecord = CamelizeKeys<DbRow<"newsletter_settings">>;
export type NewsletterSubscriberRecord = CamelizeKeys<DbRow<"newsletter_subscribers">>;
export type NewsletterListRecord = CamelizeKeys<DbRow<"newsletter_lists">>;
export type NewsletterTemplateRecord = CamelizeKeys<DbRow<"newsletter_templates">>;
export type NewsletterCampaignRecord = CamelizeKeys<DbRow<"newsletter_campaigns">>;
export type NewsletterSendJobRecord = CamelizeKeys<DbRow<"newsletter_send_jobs">>;
export type NewsletterSendJobStatus = "pending" | "processing" | "completed" | "failed" | "cancelled";
export type GetNewsletterSettingsResponse = {
    settings: NewsletterSettingsRecord | null;
};
export type UpdateNewsletterSettingsRequest = Partial<{
    doubleOptIn: boolean;
    trackOpens: boolean;
    trackClicks: boolean;
    fromName: string | null;
    replyToEmail: string | null;
    fromLocalpart: string;
    senderEntityType: "individual" | "company" | "llp" | "charity" | "other";
    senderDisplayName: string | null;
    senderAddressLine1: string | null;
    senderAddressLine2: string | null;
    senderAddressSource: "custom" | "business_address";
    senderCity: string | null;
    senderPostcode: string | null;
    senderCountry: string | null;
    companyRegistrationNumber: string | null;
    vatNumber: string | null;
    charityNumber: string | null;
}>;
export type UpdateNewsletterSettingsResponse = {
    settings: NewsletterSettingsRecord;
};
export type ListNewsletterTagsResponse = {
    tags: string[];
};
export type ListNewsletterSubscribersQuery = Partial<{
    limit: number;
    offset: number;
    status: "pending_confirmation" | "active" | "unsubscribed";
    suppressed: "true" | "false";
    tag: string;
    listId: string;
    search: string;
}>;
export type ListNewsletterSubscribersResponse = {
    subscribers: NewsletterSubscriberRecord[];
    count: number | null;
    limit: number;
    offset: number;
};
export type UpsertNewsletterSubscriberRequest = {
    email: string;
    firstName?: string | null;
    lastName?: string | null;
    fullName?: string | null;
    phone?: string | null;
    tags?: string[];
    listIds?: string[];
};
export type UpsertNewsletterSubscriberResponse = {
    subscriber: NewsletterSubscriberRecord;
};
export type GetNewsletterSubscriberResponse = {
    subscriber: NewsletterSubscriberRecord;
};
export type UpdateNewsletterSubscriberRequest = Partial<{
    tags: string[];
    listIds: string[];
}>;
export type UpdateNewsletterSubscriberResponse = {
    subscriber: NewsletterSubscriberRecord;
};
export type NewsletterSubscriberRectificationField = "email" | "firstName" | "lastName" | "fullName" | "phone";
export type NewsletterSubscriberContactChange = {
    field: NewsletterSubscriberRectificationField;
    before: string | null;
    after: string | null;
};
export type RectifyNewsletterSubscriberRequest = {
    expectedUpdatedAt: string;
    fields: Partial<Record<NewsletterSubscriberRectificationField, string | null>>;
    reason: string;
};
export type RectifyNewsletterSubscriberResponse = {
    status: "updated";
    subscriber: NewsletterSubscriberRecord;
    changes: NewsletterSubscriberContactChange[];
} | {
    status: "noop";
    subscriber: NewsletterSubscriberRecord;
    changes: [];
};
export type DeleteNewsletterSubscriberResponse = {
    deleted: boolean;
};
export type AnonymizeNewsletterSubscriberResponse = {
    subscriber: NewsletterSubscriberRecord;
};
export type ExportNewsletterSubscriberDataResponse = {
    bundle: {
        subscriber: NewsletterSubscriberRecord;
        lists: Array<{
            id: string;
            name: string;
        }>;
    };
};
export type ListNewsletterListsResponse = {
    lists: NewsletterListRecord[];
};
export type CreateNewsletterListRequest = {
    name: string;
    description?: string | null;
};
export type CreateNewsletterListResponse = {
    list: NewsletterListRecord;
};
export type UpdateNewsletterListRequest = {
    name?: string | null;
    description?: string | null;
};
export type UpdateNewsletterListResponse = {
    list: NewsletterListRecord;
};
export type DeleteNewsletterListResponse = {
    deleted: boolean;
};
export type ListNewsletterListMembersQuery = {
    limit?: number;
    offset?: number;
};
export type ListNewsletterListMembersResponse = {
    members: NewsletterSubscriberRecord[];
    count: number | null;
    limit: number;
    offset: number;
};
export type UpdateNewsletterListMembershipsRequest = {
    addSubscriberIds?: string[];
    removeSubscriberIds?: string[];
};
export type UpdateNewsletterListMembershipsResponse = {
    added: number;
    removed: number;
};
export type ImportNewsletterSubscribersCsvResponse = {
    result: {
        created: number;
        updated: number;
        skipped: number;
        failed: number;
        errors: Array<{
            row: number;
            field: string;
            message: string;
        }>;
    };
};
export type ExportNewsletterSubscribersCsvResponse = Blob;
export type ListNewsletterTemplatesResponse = {
    templates: NewsletterTemplateRecord[];
};
export type CreateNewsletterTemplateRequest = {
    name: string;
};
export type CreateNewsletterTemplateResponse = {
    template: NewsletterTemplateRecord;
};
export type GetNewsletterTemplateResponse = {
    template: NewsletterTemplateRecord;
};
export type UpdateNewsletterTemplateRequest = Partial<{
    name: string;
    content: unknown;
}>;
export type UpdateNewsletterTemplateResponse = {
    template: NewsletterTemplateRecord;
};
export type DeleteNewsletterTemplateResponse = {
    deleted: boolean;
};
export type PreviewNewsletterTemplateRequest = Partial<{
    subscriberId: string | null;
    utmCampaignId: string | null;
    campaignName: string | null;
}>;
export type NewsletterTemplatePreviewIssue = {
    code: "unknown_merge_tags";
    message: string;
    tags: string[];
} | {
    code: "missing_compliance_settings";
    message: string;
} | {
    code: "image_not_found";
    message: string;
    assetId: string;
} | {
    code: "invalid_template";
    message: string;
};
export type PreviewNewsletterTemplateResponse = {
    template: NewsletterTemplateRecord;
    preview: {
        subject: string;
        preheader: string | null;
        html: string;
        plainText: string;
        issues: NewsletterTemplatePreviewIssue[];
    };
};
export type NewsletterCampaignAudienceMode = "and" | "or";
export type ListNewsletterCampaignsResponse = {
    campaigns: NewsletterCampaignRecord[];
};
export type CreateNewsletterCampaignRequest = {
    name: string;
    templateId?: string | null;
};
export type CreateNewsletterCampaignResponse = {
    campaign: NewsletterCampaignRecord;
};
export type GetNewsletterCampaignResponse = {
    campaign: NewsletterCampaignRecord;
};
export type UpdateNewsletterCampaignRequest = Partial<{
    name: string;
    templateId: string | null;
    subject: string | null;
    preheader: string | null;
    audienceMode: NewsletterCampaignAudienceMode;
    audienceListIds: string[];
    audienceTags: string[];
    scheduledAt: string | null;
    timezone: string | null;
    status: "draft" | "scheduled" | "sending" | "sent" | "cancelled" | "failed";
    confirmLargeAudience: boolean;
}>;
export type UpdateNewsletterCampaignResponse = {
    campaign: NewsletterCampaignRecord;
};
export type DeleteNewsletterCampaignResponse = {
    deleted: boolean;
};
export type NewsletterCampaignRecipientsSummary = {
    count: number;
    filters: {
        audienceMode: NewsletterCampaignAudienceMode;
        audienceListIds: string[];
        audienceTags: string[];
    };
};
export type GetNewsletterCampaignRecipientsSummaryResponse = {
    summary: NewsletterCampaignRecipientsSummary;
};
export type NewsletterCampaignStats = {
    sentCount: number;
    deliveredCount: number;
    openedCount: number;
    clickedCount: number;
    bouncedCount: number;
    complainedCount: number;
    unsubscribedCount: number;
    lastActivityAt: string | null;
};
export type GetNewsletterCampaignStatsResponse = {
    stats: NewsletterCampaignStats;
};
export type SendNewsletterCampaignNowRequest = {
    confirmLargeAudience?: boolean;
};
export type SendNewsletterCampaignNowResponse = {
    campaign: NewsletterCampaignRecord;
    jobsCreated: number;
    recipients: NewsletterCampaignRecipientsSummary;
};
export type TestSendNewsletterCampaignRequest = {
    to: string[];
};
export type TestSendNewsletterCampaignResponse = {
    sent: number;
    failed: number;
};
export type ListNewsletterSendJobsQuery = Partial<{
    campaignId: string;
    status: NewsletterSendJobStatus;
}>;
export type ListNewsletterSendJobsResponse = {
    jobs: NewsletterSendJobRecord[];
};
export type RetryNewsletterSendJobResponse = {
    job: NewsletterSendJobRecord;
};
export type CancelNewsletterSendJobResponse = {
    job: NewsletterSendJobRecord;
};
