# Скопіювати експорт ChatGPT у фіксовані імена для кейсу Astra Portrait.
# Шукає PNG у Cursor workspaceStorage (...User\workspaceStorage\*\images) за часом у назві 00_47_33 / 00_47_34.
# Запуск:  .\tools\copy_astra_chatgpt_png.ps1
$dst = Join-Path $PSScriptRoot "..\assets\images\projects"
if (-not (Test-Path $dst)) { New-Item -ItemType Directory -Path $dst -Force | Out-Null }

$patterns = @(
  @{ Pattern = '*00_47_33 (2)*.png'; Out = 'astra-portrait-hero.png' }
  @{ Pattern = '*00_47_33 (1)*.png'; Out = 'astra-portrait-desktop.png' }
  @{ Pattern = '*00_47_34 (4)*.png'; Out = 'astra-portrait-mobile.png' }
  @{ Pattern = '*00_47_34 (3)*.png'; Out = 'astra-portrait-details.png' }
  @{ Pattern = '*00_47_34 (5)*.png'; Out = 'astra-portrait-editorial.png' }
)

$roots = @(
  "$env:APPDATA\Cursor\User\workspaceStorage",
  "$env:USERPROFILE\.cursor\projects"
)

foreach ($row in $patterns) {
  $found = $null
  foreach ($root in $roots) {
    if (-not (Test-Path $root)) { continue }
    $found = Get-ChildItem $root -Recurse -File -Filter $row.Pattern -ErrorAction SilentlyContinue |
      Sort-Object LastWriteTime -Descending | Select-Object -First 1
    if ($found) { break }
  }
  if ($found) {
    Copy-Item $found.FullName (Join-Path $dst $row.Out) -Force
    Write-Host "OK $($row.Out) <= $($found.Name)"
  } else {
    Write-Host "SKIP $($row.Out) — не знайдено $($row.Pattern)"
  }
}
