import { describe, expect, it } from 'vitest'
import * as publishedCore from '../../index'
import * as publishedOrganizationModel from '../published'

describe('published organization-model barrel zero-leak guard', () => {
  it('does not export Elevasis instance data through @repo/core/organization-model', () => {
    expect(Object.keys(publishedOrganizationModel)).not.toEqual(
      expect.arrayContaining([
        'LEAD_GEN_STAGE_CATALOG',
        'CRM_ACTION_ENTRIES',
        'LEAD_GEN_ACTION_ENTRIES',
        'CRM_PIPELINE_DEFINITION',
        'CRM_DISCOVERY_REPLIED_STATE',
        'CRM_DISCOVERY_LINK_SENT_STATE',
        'CRM_DISCOVERY_NUDGING_STATE',
        'CRM_DISCOVERY_BOOKING_CANCELLED_STATE',
        'CRM_REPLY_SENT_STATE',
        'CRM_FOLLOWUP_1_SENT_STATE',
        'CRM_FOLLOWUP_2_SENT_STATE',
        'CRM_FOLLOWUP_3_SENT_STATE',
        'CRM_PRIORITY_BUCKETS',
        'DEFAULT_CRM_PRIORITY_RULE_CONFIG',
        'DEFAULT_CRM_NEXT_ACTION_RULE_CONFIG'
      ])
    )

    const serializedExports = JSON.stringify(publishedOrganizationModel)

    expect(serializedExports).not.toContain('lgn-01c-apollo-import-workflow')
    expect(serializedExports).not.toContain('lgn-05-email-verification-workflow')
    expect(serializedExports).not.toContain('localServices')
    expect(serializedExports).not.toContain('dtcApolloClickup')
    expect(serializedExports).not.toContain('Elevasis')
    expect(serializedExports).not.toContain('elevasis.io')
    expect(serializedExports).not.toContain('discovery_replied')
    expect(serializedExports).not.toContain('discovery_link_sent')
    expect(serializedExports).not.toContain('crm-send-booking-link-workflow')
  })

  it('does not expose Elevasis CRM stage data through the @repo/core root barrel', () => {
    expect(Object.keys(publishedCore)).not.toEqual(
      expect.arrayContaining([
        'CRM_PIPELINE_DEFINITION',
        'CRM_DISCOVERY_REPLIED_STATE',
        'CRM_DISCOVERY_LINK_SENT_STATE',
        'CRM_DISCOVERY_NUDGING_STATE',
        'CRM_DISCOVERY_BOOKING_CANCELLED_STATE',
        'CRM_REPLY_SENT_STATE',
        'CRM_FOLLOWUP_1_SENT_STATE',
        'CRM_FOLLOWUP_2_SENT_STATE',
        'CRM_FOLLOWUP_3_SENT_STATE',
        'CRM_PRIORITY_BUCKETS',
        'DEFAULT_CRM_PRIORITY_RULE_CONFIG',
        'DEFAULT_CRM_NEXT_ACTION_RULE_CONFIG',
        'DEFAULT_CRM_ACTIONS'
      ])
    )

    let legacyCrmStatesResult: unknown
    try {
      legacyCrmStatesResult = (
        publishedCore as typeof publishedCore & {
          getCrmStatesForStage?: (stageKey: string) => unknown
        }
      ).getCrmStatesForStage?.('interested')
    } catch {
      legacyCrmStatesResult = undefined
    }

    expect(JSON.stringify(legacyCrmStatesResult ?? null)).not.toContain('discovery_replied')
    const serializedRootExports = JSON.stringify(publishedCore)
    expect(serializedRootExports).not.toContain('discovery_replied')
    expect(serializedRootExports).not.toContain('discovery_link_sent')
    expect(serializedRootExports).not.toContain('crm-send-booking-link-workflow')
  })
})
