<#
.SYNOPSIS
  Sync extension source files into this repo (no git operations).

.DESCRIPTION
  Copies the latest files from the source directories into the repo.
  Source root is read from $env:AUDIO_SOURCE_ROOT (no sensitive data in this script).

  Source layout expected under $env:AUDIO_SOURCE_ROOT:
    Google Meet Transcripts & AI Summary/   -> google-meet-transcripts-extension/
    caption-extension/                       -> caption-extension/

.EXAMPLE
  $env:AUDIO_SOURCE_ROOT = "D:\projects\google_meet_captions"
  .\deploy\scripts\sync.ps1
#>
[CmdletBinding()]
param()

$ErrorActionPreference = "Stop"

$sourceRoot = $env:AUDIO_SOURCE_ROOT
if (-not $sourceRoot) {
    Write-Error "Set `$env:AUDIO_SOURCE_ROOT` to the google_meet_captions folder before running."
}

$repoRoot = Split-Path (Split-Path $PSScriptRoot)   # deploy/scripts -> repo root

$mappings = @(
    @{
        From = Join-Path $sourceRoot "Google Meet Transcripts & AI Summary"
        To   = Join-Path $repoRoot "google-meet-transcripts-extension"
    },
    @{
        From = Join-Path $sourceRoot "caption-extension"
        To   = Join-Path $repoRoot "caption-extension"
    }
)

foreach ($m in $mappings) {
    if (-not (Test-Path $m.From)) {
        Write-Warning "Source not found, skipping: $($m.From)"
        continue
    }
    Write-Host "Syncing $($m.From) -> $($m.To)"
    New-Item -ItemType Directory -Force -Path $m.To | Out-Null
    Copy-Item "$($m.From)\*" $m.To -Recurse -Force
}

Write-Host "Sync complete."
