import { DomainEvent } from '../event-bus.protocol.js';
import '../../../types/drizzle.js';
import 'drizzle-orm/node-postgres';

/** Emitted after a contact row is committed. */
interface ContactCreatedEvent extends DomainEvent {
    readonly type: 'contact_created';
    readonly aggregateType: 'contact';
    readonly payload: {
        accountId: string | null;
        contactId: string;
        createdBy: string;
    };
}
interface ContactMarkedChampionEvent extends DomainEvent {
    readonly type: 'contact_marked_champion';
    readonly aggregateType: 'contact';
    readonly payload: {
        contactId: string;
        opportunityId: string;
    };
}
interface ContactMergedEvent extends DomainEvent {
    readonly type: 'contact_merged';
    readonly aggregateType: 'contact';
    readonly payload: {
        mergedBy: string;
        sourceId: string;
        targetId: string;
    };
}
/** A CRM sync run kicked off (audit/observational, not bridge-eligible). */
interface CrmSyncStartedEvent extends DomainEvent {
    readonly type: 'crm_sync_started';
    readonly aggregateType: 'crm_sync_started';
    readonly payload: {
        runId: string;
        source: string;
    };
}
interface DealCreatedEvent extends DomainEvent {
    readonly type: 'deal_created';
    readonly aggregateType: 'deal';
    readonly payload: {
        accountId: string;
        dealId: string;
        ownerId: string;
    };
}
interface DealStageChangedEvent extends DomainEvent {
    readonly type: 'deal_stage_changed';
    readonly aggregateType: 'deal';
    readonly payload: {
        dealId: string;
        newStage: string;
        oldStage: string;
    };
}
/** Stripe charge.succeeded webhook, post-signature-verification. */
interface StripePaymentReceivedEvent extends DomainEvent {
    readonly type: 'stripe_payment_received';
    readonly aggregateType: 'stripe';
    readonly payload: {
        amountCents: number;
        currency: string;
        customerId: string;
        /** Stripe event id (evt_...) */
        eventId: string;
        receivedAt: Date;
    };
}
/** Outbound notification to the configured CRM when a contact changes. */
interface WebhookOutboundContactSyncEvent extends DomainEvent {
    readonly type: 'webhook_outbound_contact_sync';
    readonly aggregateType: 'contact';
    readonly payload: {
        contactId: string;
        occurredAt: Date;
        /** create | update | delete */
        operation: string;
    };
}
type AppDomainEvent = ContactCreatedEvent | ContactMarkedChampionEvent | ContactMergedEvent | CrmSyncStartedEvent | DealCreatedEvent | DealStageChangedEvent | StripePaymentReceivedEvent | WebhookOutboundContactSyncEvent;
type EventTypeName = AppDomainEvent['type'];
type EventOfType<T extends EventTypeName> = Extract<AppDomainEvent, {
    type: T;
}>;
type PayloadOfType<T extends EventTypeName> = EventOfType<T>['payload'];

export type { AppDomainEvent, ContactCreatedEvent, ContactMarkedChampionEvent, ContactMergedEvent, CrmSyncStartedEvent, DealCreatedEvent, DealStageChangedEvent, EventOfType, EventTypeName, PayloadOfType, StripePaymentReceivedEvent, WebhookOutboundContactSyncEvent };
