#!/usr/bin/env python3
"""Inject the 'pool of comp clients' concern + revise onboarding date language."""
import re

ROOT = "/home/sol1/Desktop/MARKETING/nitrous_3mo"
with open(f"{ROOT}/ZAP_NOTICE.html") as f:
    html = f.read()

# Build new section to add as Section 7 (between current 6 and 7)
new_section = """
<h3><span class="num">7.</span>Standardised template vs bespoke programme — what the campaign naming reveals</h3>

<p>This is the second concern, and it's tied to the first. We've reviewed Zap's campaign naming convention as visible in our WooCommerce attribution metadata, and the structure tells us something important:</p>

<table>
  <thead><tr><th>Campaign name from your account</th><th>What the structure reveals</th></tr></thead>
  <tbody>
    <tr><td><code>Meg | Zap | MOF | Sales | All Draws | UK (Excl. CusList MoM)</code></td><td>Strategist initial + agency name + funnel stage + objective + variant + geo + standard exclusion</td></tr>
    <tr><td><code>Zap | MOF | Spotlight | Renault Racetruck | Ends 27th Feb @ 22:30PM</code></td><td>Templated "Spotlight" naming with prize variable + end date</td></tr>
    <tr><td><code>Zap | BOF | Sales | UK | Loyalty (Customers) (feed)</code></td><td>BOF / Loyalty / Customers — taxonomy lifted from agency playbook</td></tr>
    <tr><td><code>Zap | TOF | Traffic (LPVs) | UK (Excl. CusList MoM) - Winners Content</code></td><td>TOF / Traffic / LPV / Month-over-Month exclusion — formula structure</td></tr>
    <tr><td><code>ON_Zap_BOF_Sales_UK_Loyalty</code></td><td>Same campaign re-launched with underscore taxonomy — duplicate setup</td></tr>
  </tbody>
</table>

<p>The taxonomy is consistent and templated: <strong>Brand-prefix | Funnel-stage | Campaign-type | Audience | Geo | Exclusion</strong>. Within the {NUM_CAMPS} active campaigns, the same pattern repeats with prize names and dates as variables.</p>

<div class="pull warn">
  <div class="small">Our concern</div>
  This naming structure is consistent with a templated agency programme — the same playbook applied across multiple competition-site clients with the prize and date as variables. We don't believe this is bespoke to Nitrous Competitions. The "Hosting Package 11" line on your invoices reinforces this — packages numbered 1 through 11+ suggest a tiered, productised service designed to serve a pool of clients efficiently rather than a programme built specifically for any single one.
</div>

<p>We've also been unable to find evidence in the campaign data of:</p>
<ul class="cleanlist">
  <li>A Lookalike-1% audience seeded from <em>our</em> top customer LTV file (the 5,898 customers who spent £100+ in the last 90 days)</li>
  <li>Custom Audiences built from <em>our</em> Klaviyo high-intent segments (e.g. "High Intent Cash Players", "High Intent Car/Bike Players")</li>
  <li>Creative rotation specific to <em>our</em> top-performing email subject lines (the words "Last Chance", "£5,000", "Wins" outperform on email and would translate to Meta)</li>
  <li>A separate Account Credit / Zap-Cashier-aware acquisition flow — despite this being one of our core mechanics</li>
  <li>A Welcome Flow tailored to Nitrous's specific competition cadence</li>
</ul>

<p>We acknowledge a templated agency model can deliver scale efficiency, and we're not criticising the approach — for some clients, it's exactly right. But for Nitrous at our current size and complexity (442k customer database, 587 active SKUs, ~£12M annual run-rate, instant-win mechanics, account-credit system), <strong>we believe we need a programme built around our specifics rather than an instance of a shared model</strong>.</p>

<div class="pull">
  <div class="small">In plain English</div>
  We don't believe Zap has Nitrous's specific interests at the centre of the marketing programme. We believe Nitrous is one client in a pool of competition companies running on the same template — and that template, while standardised and efficient for Zap, is no longer producing the bespoke results Nitrous needs at this scale. The data above (frequency, malformed UTMs, 86 dead campaigns, missing CRM-driven lookalikes, 28 Klaviyo flows in DRAFT) collectively support that view.
</div>

<p>We'd respectfully ask Zap to confirm the following in writing as part of the handover:</p>
<ul class="cleanlist">
  <li>Confirmation of <strong>which other UK competition / prize-draw operators</strong> Zap currently manages or has managed in the last 24 months (so we can be confident our data, audiences and creative are not being co-mingled)</li>
  <li>Confirmation that <strong>no Custom Audience built from Nitrous customer data</strong> has been used to seed campaigns for other Zap clients (lookalike audiences across competing brands would be a material conflict)</li>
  <li>Confirmation of the <strong>data-handling practice</strong> applied to our Meta Pixel + CAPI events when it sits inside an agency-shared Business Manager</li>
</ul>
"""

NUM_CAMPS = 180  # from data
new_section = new_section.replace("{NUM_CAMPS}", str(NUM_CAMPS))

# Find Section 7 in current HTML (which is "The cost structure")
# We need to insert BEFORE the cost structure section
# Section 7 currently says "<h3><span class="num">7.</span>The cost structure"
# We'll insert the pool concern as new section 7, push existing forward
import re
# The pattern: existing "<h3><span class="num">7.</span>The cost structure"
match = re.search(r'<h3><span class="num">7\.</span>The cost structure', html)
if match:
    insert_pos = match.start()
    # Renumber existing 7, 8, 9 to 8, 9, 10
    html_after = html[insert_pos:]
    html_after = re.sub(r'<h3><span class="num">7\.</span>', '<h3><span class="num">8.</span>', html_after, count=1)
    html_after = re.sub(r'<h3><span class="num">8\.</span>Transition handover', '<h3><span class="num">9.</span>Transition handover', html_after, count=1)
    html_after = re.sub(r'<h3><span class="num">9\.</span>Closing', '<h3><span class="num">10.</span>Closing', html_after, count=1)
    html = html[:insert_pos] + new_section + html_after

# Update the engagement timeline section to use exact data-confirmed language
# Find "Your first Advantage+ Shopping Campaign" and tighten the language
html = html.replace(
    "Your first Advantage+ Shopping Campaign — confirmed in our WooCommerce attribution metadata as <code>Advantage++shopping+campaign+19/04/2024+Campaign</code> — went live on <strong>19 April 2024</strong>. That's <strong>2 years and 18 days as of today</strong>.",
    """The earliest verifiable date of Zap's paid-media activity in our WooCommerce attribution data is <strong>19 April 2024</strong> — confirmed by your own UTM <code>Advantage++shopping+campaign+19/04/2024+Campaign</code>, which embeds the launch date in the campaign name. That's the start of <strong>year 3</strong> of the engagement.<br><br>If the formal contract / hosting onboarding pre-dates this, please confirm the exact start date in writing — we'll update our records. The 19 April 2024 date is what's evidenced in our paid-media data; the hosting / Package 11 engagement may go back further."""
)

with open(f"{ROOT}/ZAP_NOTICE.html","w") as f:
    f.write(html)

import os
print(f"Updated ZAP_NOTICE.html: {os.path.getsize(f'{ROOT}/ZAP_NOTICE.html'):,} bytes")
