const { Client, GatewayIntentBits } = require('discord.js');
const fs = require('fs');
const path = require('path');

const configPath = path.join(process.env.HOME, '.clawdbot', 'clawdbot.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const token = config.channels?.discord?.token;

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const forums = {
  distribution: '1464923072724209780',
  networking: '1464923074813231126', 
  promotion: '1464923073827573854',
  production: '1464923072392855653',
  business: '1464923075589046437',
  hq: '1464923076583227406',
  resources: '1464918799470956723',
  analytics: '1464923071096815690'
};

const threads = [
  {
    forum: 'promotion',
    name: '📱 Content Ideas',
    message: `**TikTok & Social Content Strategy**

## Content Pillars
1. **Music Snippets (40%)** — Track previews, remixes, unreleased
2. **Production (25%)** — How I made X, sound design, Ableton tips
3. **Personal (20%)** — Day in the life, shows, authentic moments
4. **Trends (15%)** — Relevant TikTok trends, tie back to music

## Quick Win Ideas
- [ ] "POV: you just dropped your first album" + Surya clip
- [ ] Sound design breakdown of Polynesian groove
- [ ] "What genre is this?" game
- [ ] Before/after production clips
- [ ] "Artists that influenced Surya" tier list

## Posting Schedule
- TikTok: 1-2x daily during push
- IG Feed: 2-3x weekly
- IG Stories: Daily
- Twitter: Daily engagement

## Das's Specialty: Trippy Edits
- Visualizers for tracks
- Album art animations
- High-quality > low-quality (but balance with consistency)`
  },
  {
    forum: 'analytics',
    name: '📈 Spotify Stats',
    message: `**Spotify Performance Tracking**

## Current Stats (January 2026)
- Monthly Listeners: 581
- Followers: [check Spotify for Artists]
- Top Cities: [TBD]
- Top Countries: [TBD]

## Targets
| Timeframe | Listeners |
|-----------|-----------|
| 1 month | 1,000 |
| 3 months | 3,000 |
| 6 months | 10,000 |
| 12 months | 100,000 |

## Playlist Adds
| Playlist | Added Date | Streams |
|----------|-----------|---------|
| | | |

---

Update weekly from Spotify for Artists.`
  },
  {
    forum: 'analytics',
    name: '📊 Weekly Analytics Roundup',
    message: `**Weekly Stats Template**

## Week of [DATE]

### Streaming
- Spotify Monthly: 
- Spotify Weekly Streams:
- SoundCloud Plays:

### Social
- TikTok Followers:
- TikTok Views (week):
- IG Followers:
- IG Reach:

### Ads
- Spend: $
- Clicks:
- Cost per click: $
- New listeners (est):

### Wins
- 

### What Worked
- 

### What to Try Next Week
- 

---

Copy this template each week!`
  },
  {
    forum: 'hq',
    name: '📝 Meeting Notes',
    message: `**Meeting Notes & Planning Sessions**

## Kickoff - January 2026

**Attendees:** Jake, Dylan

**Discussed:**
- Discord server structure for artist development
- Priority matrix for all activities
- 6-month and 12-month goals
- Tool integrations (Buba, analytics, etc.)

**Action Items:**
- [ ] Dylan to fill out forum threads with current status
- [ ] Start DJ mix for booking pitches
- [ ] Set up Spotify for Artists tracking
- [ ] Review ad strategy

---

Add notes from each sync!`
  },
  {
    forum: 'networking',
    name: '🎪 Upcoming Events',
    message: `**Events to Attend / Network At**

## January 2026
| Event | Date | Venue | Who to Meet | Notes |
|-------|------|-------|-------------|-------|
| | | | | |

## Recurring
- **Space Yacht Tuesdays** — Sound Nightclub
- **Brownies & Lemonade** — Various (check IG)

## Festivals to Watch
- HARD Summer
- Day of the Dead
- Coachella (dream, long-term)

---

Add events as you find them. Note who you want to meet!`
  }
];

async function createThreads() {
  await client.login(token);
  console.log('Logged in as', client.user.tag);

  for (const thread of threads) {
    try {
      const channel = await client.channels.fetch(forums[thread.forum]);
      const created = await channel.threads.create({
        name: thread.name,
        message: { content: thread.message }
      });
      console.log('Created thread:', thread.name, 'in', thread.forum);
    } catch (err) {
      console.error('Error:', thread.name, err.message);
    }
  }

  console.log('Done!');
  client.destroy();
  process.exit(0);
}

createThreads();
