import type { B2BTemplate, B2BHit, B2BSettings, B2BTenant } from './types'

// ============================================
// HECTRONIC TEMPLATE (Real Example)
// ============================================

export const hectronicTemplate: B2BTemplate = {
  templateId: 'tpl_hectronic_public_procurement_v1',
  templateName: 'Hectronic – Kommunale Ausschreibungen (Parking • EV Charging • Fuel)',
  templateDescription: 'Findet weltweit kommunale Ausschreibungen für Parkscheinautomaten/Parkraummanagement, Payment an Ladepunkten und Fuel-Terminals. Reduziert News/Jobs/Zubehör-Rauschen stark.',
  targetRoles: ['sales_ops', 'bid_management', 'product_marketing', 'regional_sales'],
  industry: 'Payment & Infrastructure',
  companyExample: 'Hectronic GmbH',
  guidedConfig: {
    regionSelector: {
      type: 'multi_select',
      default: ['EUROPE'],
      options: ['EUROPE', 'DACH', 'NORTH_AMERICA', 'MIDDLE_EAST', 'APAC', 'GLOBAL']
    },
    languageSelector: {
      type: 'multi_select',
      default: ['de', 'en'],
      options: ['de', 'en', 'fr', 'es', 'it', 'nl', 'pl', 'sv', 'da', 'no', 'fi', 'pt']
    },
    packageSelector: {
      type: 'multi_select',
      default: ['PARKING', 'EV_CHARGING'],
      options: ['PARKING', 'EV_CHARGING', 'FUEL', 'TANK_MONITORING']
    },
    noiseMode: {
      type: 'single_select',
      default: 'STRICT',
      options: ['STRICT', 'BALANCED', 'BROAD']
    }
  },
  topics: [
    {
      name: 'Parking – Parkscheinautomaten & Parkraummanagement (Kommunen)',
      package: 'PARKING',
      intent: {
        goalStatement: 'Finde kommunale Ausschreibungen/Procurements für Parkscheinautomaten, Pay Stations, Parkraummanagement-Software und zugehörige Services.',
        mustHaveAnyN: 2,
        mustHave: [
          { type: 'keyword', value: 'parking meter' },
          { type: 'keyword', value: 'pay and display' },
          { type: 'keyword', value: 'parking pay station' },
          { type: 'keyword', value: 'Parkscheinautomat' },
          { type: 'keyword', value: 'Parkautomat' },
          { type: 'keyword', value: 'Parkraumbewirtschaftung' },
          { type: 'keyword', value: 'backoffice' },
          { type: 'keyword', value: 'management software' }
        ],
        publicBuyerSignalsAny: [
          'municipality', 'city', 'city council', 'local authority', 'public tender',
          'Kommune', 'Stadt', 'Gemeinde', 'Landkreis', 'öffentliche Ausschreibung', 'Vergabe'
        ],
        procurementSignalsAny: [
          'tender', 'procurement', 'RFP', 'RFQ', 'invitation to tender', 'contract notice',
          'Ausschreibung', 'Vergabe', 'EU-weite Ausschreibung', 'Bekanntmachung'
        ]
      },
      filters: {
        hardExcludesAny: [
          'keyboard', 'mouse', 'headset', 'toner', 'office supplies',
          'Tastatur', 'Maus', 'Headset', 'Büromaterial',
          'job', 'hiring', 'stellenanzeige', 'bewerbung',
          'parking fine', 'parking ticket', 'Strafzettel', 'Knöllchen'
        ],
        softExcludesAny: [
          'press release', 'marketing', 'blog', 'opinion',
          'pressemitteilung', 'werbung', 'meinung',
          'maintenance only', 'consulting only', 'support only'
        ]
      },
      decisionPolicy: {
        rulesFirst: true,
        llmMode: 'GRAYZONE_ONLY',
        autoRelevantMinConf: 0.80,
        needsReviewRange: [0.50, 0.79],
        autoIrrelevantMaxConf: 0.49
      },
      importanceModelId: 'imp_hectronic_v1',
      status: 'active'
    },
    {
      name: 'EV Charging – Payment/Terminals in kommunaler Ladeinfrastruktur',
      package: 'EV_CHARGING',
      intent: {
        goalStatement: 'Finde kommunale Ausschreibungen für Ladeinfrastruktur mit Payment-Terminals, Ad-hoc-Kartenzahlung, Backend/Management.',
        mustHaveAnyN: 2,
        mustHave: [
          { type: 'keyword', value: 'EV charging' },
          { type: 'keyword', value: 'charging station' },
          { type: 'keyword', value: 'charge point' },
          { type: 'keyword', value: 'Ladesäule' },
          { type: 'keyword', value: 'Ladeinfrastruktur' },
          { type: 'keyword', value: 'payment terminal' },
          { type: 'keyword', value: 'card payment' },
          { type: 'keyword', value: 'contactless' },
          { type: 'keyword', value: 'Bezahlsystem' },
          { type: 'keyword', value: 'Kartenzahlung' }
        ],
        publicBuyerSignalsAny: [
          'municipality', 'city', 'public works', 'local authority',
          'Kommune', 'Stadt', 'Gemeinde', 'Kommunal'
        ],
        procurementSignalsAny: [
          'tender', 'procurement', 'RFP', 'RFQ', 'contract notice',
          'Ausschreibung', 'Vergabe', 'Bekanntmachung'
        ]
      },
      filters: {
        hardExcludesAny: [
          'stock', 'investor', 'funding round', 'press release',
          'Aktie', 'Investor', 'Finanzierung', 'Pressemitteilung',
          'job', 'hiring', 'stellenanzeige',
          'private home charger', 'wallbox'
        ],
        softExcludesAny: [
          'funding program', 'grant', 'Förderprogramm', 'Zuschuss',
          'pilot project', 'research project', 'Modellprojekt'
        ]
      },
      decisionPolicy: {
        rulesFirst: true,
        llmMode: 'GRAYZONE_ONLY',
        autoRelevantMinConf: 0.80,
        needsReviewRange: [0.50, 0.79],
        autoIrrelevantMaxConf: 0.49
      },
      importanceModelId: 'imp_hectronic_v1',
      status: 'active'
    },
    {
      name: 'Fuel – Fleet/Public Fuel Terminals',
      package: 'FUEL',
      intent: {
        goalStatement: 'Finde Ausschreibungen für (un)bemannte Tankautomaten/Fuel-Terminals, Fuel-Management, Flottenbetankung.',
        mustHaveAnyN: 2,
        mustHave: [
          { type: 'keyword', value: 'fuel terminal' },
          { type: 'keyword', value: 'fuel management' },
          { type: 'keyword', value: 'unmanned fuel station' },
          { type: 'keyword', value: 'fleet fueling' },
          { type: 'keyword', value: 'Tankautomat' },
          { type: 'keyword', value: 'Tankterminal' },
          { type: 'keyword', value: 'Flottenbetankung' },
          { type: 'keyword', value: 'Betriebstankstelle' }
        ],
        publicBuyerSignalsAny: ['municipality', 'utilities', 'public works', 'Stadtwerke', 'Kommunal'],
        procurementSignalsAny: ['tender', 'procurement', 'RFP', 'Ausschreibung', 'Vergabe']
      },
      filters: {
        hardExcludesAny: ['fuel price', 'oil price', 'Spritpreise', 'Ölpreis', 'job', 'hiring', 'stellenanzeige'],
        softExcludesAny: ['market news', 'commodity', 'Börse', 'Pressemitteilung']
      },
      decisionPolicy: {
        rulesFirst: true,
        llmMode: 'GRAYZONE_ONLY',
        autoRelevantMinConf: 0.80,
        needsReviewRange: [0.50, 0.79],
        autoIrrelevantMaxConf: 0.49
      },
      importanceModelId: 'imp_hectronic_v1',
      status: 'active'
    }
  ],
  importanceModel: {
    modelId: 'imp_hectronic_v1',
    scoreRange: [0, 100],
    weights: {
      deadlineProximity: 28,
      procurementIntentStrength: 22,
      publicBuyerStrength: 18,
      productMatchStrength: 18,
      sourceTrust: 8,
      novelty: 6
    },
    thresholds: {
      infoMax: 29,
      reviewMin: 30,
      importantMin: 50,
      urgentMin: 70,
      criticalMin: 85
    },
    topNCaps: {
      dailyDigestMax: 10,
      weeklyDigestMax: 20,
      perTopicDailyMax: 6
    }
  },
  notificationPreset: {
    presetId: 'notif_hectronic_digest_v1',
    channels: ['email'],
    cadence: 'DAILY',
    timeLocal: '08:00',
    includeStatuses: ['relevant', 'needs_review'],
    maxItems: 10
  }
}

// ============================================
// MOCK DATA (Demo Hits for Hectronic)
// ============================================

export const mockHectronicHits: B2BHit[] = [
  {
    id: 'hit-hec-001',
    tenantId: 'hectronic-demo',
    topicId: 'hec_parking_v1',
    sourceType: 'email',
    sourceRef: 'ga-msg-001',
    originalUrl: 'https://www.evergabe.de/auftraege/parkscheinautomaten-stadt-muenchen',
    canonicalUrl: 'https://evergabe.de/auftraege/parkscheinautomaten-muenchen',
    title: 'Stadt München: Lieferung und Installation von 150 Parkscheinautomaten',
    snippet: 'Die Landeshauptstadt München schreibt die Beschaffung von 150 modernen Parkscheinautomaten inkl. Backoffice-Software für das Stadtgebiet aus. Frist: 15.03.2026.',
    foundAt: new Date(Date.now() - 2 * 60 * 60 * 1000),
    language: 'de',
    countryGuess: 'Germany',
    buyerGuess: 'Landeshauptstadt München',
    deadlineGuess: '2026-03-15',
    importanceScore: 92,
    importanceLabel: 'KRITISCH',
    decisionLabel: 'relevant',
    decisionConfidence: 0.95,
    decisionTrace: {
      rulesTriggered: ['procurement_signal_match', 'public_buyer_match', 'product_match'],
      llmUsed: false,
      signals: {
        procurementSignalsFound: ['Ausschreibung', 'Beschaffung', 'Vergabe'],
        publicBuyerSignalsFound: ['Landeshauptstadt', 'Stadt München'],
        productSignalsFound: ['Parkscheinautomaten', 'Backoffice-Software'],
        negativesFound: []
      }
    },
    isRead: false,
    createdAt: new Date(Date.now() - 2 * 60 * 60 * 1000)
  },
  {
    id: 'hit-hec-002',
    tenantId: 'hectronic-demo',
    topicId: 'hec_ev_charging_v1',
    sourceType: 'rss',
    sourceRef: 'rss-item-002',
    originalUrl: 'https://ted.europa.eu/notice/2026-12345',
    canonicalUrl: 'https://ted.europa.eu/notice/2026-12345',
    title: 'EU Tender: Supply of EV Charging Infrastructure with Payment Terminals - City of Amsterdam',
    snippet: 'Contract notice for the supply, installation and maintenance of 200 public EV charging points with integrated contactless payment terminals. Deadline: 28.02.2026.',
    foundAt: new Date(Date.now() - 5 * 60 * 60 * 1000),
    language: 'en',
    countryGuess: 'Netherlands',
    buyerGuess: 'City of Amsterdam',
    deadlineGuess: '2026-02-28',
    importanceScore: 88,
    importanceLabel: 'KRITISCH',
    decisionLabel: 'relevant',
    decisionConfidence: 0.92,
    decisionTrace: {
      rulesTriggered: ['procurement_signal_match', 'public_buyer_match', 'product_match'],
      llmUsed: false,
      signals: {
        procurementSignalsFound: ['Contract notice', 'tender', 'supply'],
        publicBuyerSignalsFound: ['City of Amsterdam', 'public'],
        productSignalsFound: ['EV charging', 'charging points', 'payment terminals', 'contactless'],
        negativesFound: []
      }
    },
    isRead: false,
    createdAt: new Date(Date.now() - 5 * 60 * 60 * 1000)
  },
  {
    id: 'hit-hec-003',
    tenantId: 'hectronic-demo',
    topicId: 'hec_parking_v1',
    sourceType: 'email',
    sourceRef: 'ga-msg-003',
    originalUrl: 'https://vergabe.niedersachsen.de/NetServer/notice/8765432',
    canonicalUrl: 'https://vergabe.niedersachsen.de/notice/8765432',
    title: 'Gemeinde Seevetal: Erneuerung Parkraumbewirtschaftungssystem',
    snippet: 'Öffentliche Ausschreibung zur Erneuerung des Parkraumbewirtschaftungssystems mit 25 Pay-Stations und zentraler Management-Software.',
    foundAt: new Date(Date.now() - 8 * 60 * 60 * 1000),
    language: 'de',
    countryGuess: 'Germany',
    buyerGuess: 'Gemeinde Seevetal',
    deadlineGuess: '2026-04-01',
    importanceScore: 78,
    importanceLabel: 'DRINGEND',
    decisionLabel: 'relevant',
    decisionConfidence: 0.88,
    decisionTrace: {
      rulesTriggered: ['procurement_signal_match', 'public_buyer_match', 'product_match'],
      llmUsed: false,
      signals: {
        procurementSignalsFound: ['Öffentliche Ausschreibung', 'Erneuerung'],
        publicBuyerSignalsFound: ['Gemeinde'],
        productSignalsFound: ['Parkraumbewirtschaftungssystem', 'Pay-Stations', 'Management-Software'],
        negativesFound: []
      }
    },
    isRead: false,
    createdAt: new Date(Date.now() - 8 * 60 * 60 * 1000)
  },
  {
    id: 'hit-hec-004',
    tenantId: 'hectronic-demo',
    topicId: 'hec_parking_v1',
    sourceType: 'email',
    sourceRef: 'ga-msg-004',
    originalUrl: 'https://news.example.com/parking-industry-trends-2026',
    canonicalUrl: 'https://news.example.com/parking-trends-2026',
    title: 'Parking Industry Trends 2026: Smart Cities investieren in digitale Lösungen',
    snippet: 'Branchenanalyse zeigt wachsende Nachfrage nach vernetzten Parkscheinautomaten. Experten erwarten 15% Marktwachstum.',
    foundAt: new Date(Date.now() - 12 * 60 * 60 * 1000),
    language: 'de',
    countryGuess: 'Germany',
    buyerGuess: undefined,
    deadlineGuess: undefined,
    importanceScore: 15,
    importanceLabel: 'INFO',
    decisionLabel: 'irrelevant',
    decisionConfidence: 0.91,
    decisionTrace: {
      rulesTriggered: ['soft_exclude_triggered'],
      llmUsed: false,
      signals: {
        procurementSignalsFound: [],
        publicBuyerSignalsFound: [],
        productSignalsFound: ['Parkscheinautomaten'],
        negativesFound: ['Branchenanalyse', 'Experten', 'Marktwachstum']
      }
    },
    isRead: true,
    createdAt: new Date(Date.now() - 12 * 60 * 60 * 1000)
  },
  {
    id: 'hit-hec-005',
    tenantId: 'hectronic-demo',
    topicId: 'hec_ev_charging_v1',
    sourceType: 'rss',
    sourceRef: 'rss-item-005',
    originalUrl: 'https://ausschreibungen.at/ladeinfrastruktur-wien',
    canonicalUrl: 'https://ausschreibungen.at/ladeinfrastruktur-wien',
    title: 'Stadt Wien: Rahmenvertrag Ladeinfrastruktur öffentlicher Raum',
    snippet: 'Vergabeverfahren für Rahmenvertrag über Lieferung und Betrieb von Ladeinfrastruktur im öffentlichen Raum. Details hinter Login.',
    foundAt: new Date(Date.now() - 18 * 60 * 60 * 1000),
    language: 'de',
    countryGuess: 'Austria',
    buyerGuess: 'Stadt Wien',
    deadlineGuess: undefined,
    importanceScore: 55,
    importanceLabel: 'WICHTIG',
    decisionLabel: 'needs_review',
    decisionConfidence: 0.62,
    decisionTrace: {
      rulesTriggered: ['procurement_signal_match', 'public_buyer_match'],
      llmUsed: true,
      llmConfidence: 0.62,
      signals: {
        procurementSignalsFound: ['Vergabeverfahren', 'Rahmenvertrag'],
        publicBuyerSignalsFound: ['Stadt Wien', 'öffentlicher Raum'],
        productSignalsFound: ['Ladeinfrastruktur'],
        negativesFound: ['Details hinter Login']
      }
    },
    isRead: false,
    createdAt: new Date(Date.now() - 18 * 60 * 60 * 1000)
  },
  {
    id: 'hit-hec-006',
    tenantId: 'hectronic-demo',
    topicId: 'hec_fuel_v1',
    sourceType: 'email',
    sourceRef: 'ga-msg-006',
    originalUrl: 'https://vergabe.bund.de/tankautomat-bundeswehr',
    canonicalUrl: 'https://vergabe.bund.de/tankautomat-bw',
    title: 'Bundesamt für Ausrüstung: Tankautomaten für Liegenschaften',
    snippet: 'Beschaffung von unbemannten Tankautomaten für Flottenbetankung an 12 Bundeswehr-Standorten. EU-weite Ausschreibung.',
    foundAt: new Date(Date.now() - 24 * 60 * 60 * 1000),
    language: 'de',
    countryGuess: 'Germany',
    buyerGuess: 'Bundesamt für Ausrüstung',
    deadlineGuess: '2026-05-15',
    importanceScore: 72,
    importanceLabel: 'DRINGEND',
    decisionLabel: 'relevant',
    decisionConfidence: 0.86,
    decisionTrace: {
      rulesTriggered: ['procurement_signal_match', 'public_buyer_match', 'product_match'],
      llmUsed: false,
      signals: {
        procurementSignalsFound: ['Beschaffung', 'EU-weite Ausschreibung'],
        publicBuyerSignalsFound: ['Bundesamt'],
        productSignalsFound: ['Tankautomaten', 'Flottenbetankung', 'unbemannt'],
        negativesFound: []
      }
    },
    isRead: true,
    createdAt: new Date(Date.now() - 24 * 60 * 60 * 1000)
  }
]

// ============================================
// DEFAULT SETTINGS
// ============================================

export const defaultB2BSettings: B2BSettings = {
  migrationCompleted: false,
  wizardCompleted: false,
  selectedRegions: ['EUROPE'],
  selectedLanguages: ['de', 'en'],
  selectedPackages: ['PARKING', 'EV_CHARGING'],
  noiseMode: 'STRICT',
  notificationCadence: 'DAILY',
  notificationTime: '08:00',
  maxDigestItems: 10
}

export const defaultTenant: B2BTenant = {
  id: 'demo-tenant',
  name: 'Demo Account',
  companyName: 'Meine Firma GmbH',
  industry: 'Payment & Infrastructure',
  plan: 'trial',
  inboundEmailDomain: 'alerts.breakpilot.de',
  createdAt: new Date(),
  settings: defaultB2BSettings
}
