<?php
/**
 * Seed Mystic Art Tattoo demo data into data/*.json.
 * Idempotent: artists, schedules, and gallery are fully reset on every run.
 * Pulls live avatar + work images from static.wixstatic.com (they're
 * hotlinkable) and links video tiles back to mysticartatto.com.
 *
 * Usage:  php src/bin/seed.php
 */
declare(strict_types=1);

chdir(dirname(__DIR__, 2));
define('MAT_ROOT', __DIR__ . '/../..');
$config = require MAT_ROOT . '/config.php';
$GLOBALS['mat_config'] = $config;

require MAT_ROOT . '/src/autoload.php';
require MAT_ROOT . '/src/helpers.php';

$_SESSION = [];
@mkdir($config['data_path'], 0755, true);
@mkdir($config['upload_path'] . '/gallery', 0755, true);
@mkdir($config['upload_path'] . '/avatars', 0755, true);

use App\Repositories\Container;
use App\Json\FileStore;

Container::settings()->save([
    'shop_name' => 'Mystic Art Tattoo',
    'tagline_en' => 'Fine-line, realism, lettering and custom work.',
    'tagline_es' => 'Líneas finas, realismo, lettering y trabajos personalizados.',
    'address' => "179 US-46 #16\nRockaway, NJ 07866",
    'phone' => '862-596-6098',
    'email' => 'info@mysticartatto.com',
    'hours' => [
        'mon' => '09:00-16:00',
        'tue' => '09:00-16:00',
        'wed' => '09:00-16:00',
        'thu' => '09:00-16:00',
        'fri' => '09:00-16:00',
        'sat' => '10:00-14:00',
        'sun' => 'closed',
    ],
    'socials' => [
        'instagram' => 'https://www.instagram.com/mysticarttatto',
        'facebook'  => '',
        'tiktok'    => '',
        'whatsapp'  => '',
    ],
    'map_embed_url' => 'https://www.google.com/maps?q=179+US-46+%2316,+Rockaway,+NJ+07866&output=embed',
]);
echo "✓ Shop settings\n";

// Fully reset artists + schedules + gallery
(new FileStore($config['data_path'] . '/artists.json'))->write(['artists' => []]);
(new FileStore($config['data_path'] . '/schedules.json'))->write(['weekly' => [], 'exceptions' => []]);
(new FileStore($config['data_path'] . '/gallery.json'))->write(['items' => []]);

$realArtists = [
    [
        'display_name' => 'Lorenzo Diaz',
        'instagram_handle' => 'lorenzodiazink',
        'specialties' => ['realism', 'black & gray', 'lettering'],
        'bio' => 'Lead artist and owner of Mystic Art Tattoo. Over a decade of experience in realism and fine line work. Passionate about translating stories into skin.',
        'avatar_url' => 'https://static.wixstatic.com/media/a23fe6_deaca64cf5db427a81b0e3aef95b047c~mv2.png',
    ],
    [
        'display_name' => 'Jorge Jaramillo',
        'instagram_handle' => 'quazy_tattoos',
        'specialties' => ['color', 'realism', 'custom'],
        'bio' => 'Versatile artist specializing in color realism and custom designs.',
        'avatar_url' => 'https://static.wixstatic.com/media/a23fe6_758ed3e77ba2485a83303dba5ca17809~mv2.png',
    ],
    [
        'display_name' => 'Esteban Ceron',
        'instagram_handle' => 'estebanceron_art',
        'specialties' => ['fine-line', 'ornamental', 'black & gray'],
        'bio' => 'Fine-line specialist with a love for ornamental and delicate work.',
        'avatar_url' => 'https://static.wixstatic.com/media/a23fe6_1f37630ccaa34286ba846febcbce3c38~mv2.jpg',
    ],
];

$artistIds = [];
$schedules = Container::schedules();
foreach ($realArtists as $a) {
    $saved = Container::artists()->save(array_merge($a, ['is_active' => true]));
    $artistIds[$a['display_name']] = $saved['id'];
    // Weekly: Mon-Fri 9 AM-4 PM, Sat 10 AM-2 PM, Sun closed
    $rows = [];
    foreach ([1, 2, 3, 4, 5] as $wd) {
        $rows[] = ['weekday' => $wd, 'start_time' => '09:00', 'end_time' => '16:00'];
    }
    $rows[] = ['weekday' => 6, 'start_time' => '10:00', 'end_time' => '14:00'];
    $schedules->replaceWeekly($saved['id'], $rows);
    echo "✓ Artist: {$saved['display_name']} (@{$saved['instagram_handle']})\n";
}

// ---------- Gallery ----------
// Shared portfolio images from the live site (hotlinkable via static.wixstatic.com)
$portfolio = [
    ['Lorenzo Diaz',  'https://static.wixstatic.com/media/a23fe6_9733102241814c5585e502791b3582fdf002.jpg'],
    ['Lorenzo Diaz',  'https://static.wixstatic.com/media/a23fe6_c79134f7bf944e6f8f7a8194b2f59503f002.jpg'],
    ['Lorenzo Diaz',  'https://static.wixstatic.com/media/a23fe6_089bab3253654951bba30e6a2d54a5a7f002.jpg'],
    ['Esteban Ceron', 'https://static.wixstatic.com/media/a23fe6_894faeee100346da8dc7222c13a96de0f002.jpg'],
    ['Esteban Ceron', 'https://static.wixstatic.com/media/a23fe6_f6853c38742b4876ba8ce71da0fc5971f002.jpg'],
    ['Esteban Ceron', 'https://static.wixstatic.com/media/a23fe6_398ce04101a644faab151fc01b2ec9a9f002.jpg'],
    ['Jorge Jaramillo','https://static.wixstatic.com/media/a23fe6_8d7af4d79b3d4d8192f0d6cd1524d4faf002.jpg'],
    ['Jorge Jaramillo','https://static.wixstatic.com/media/a23fe6_f5ea9a5059304a43adcd4478fc5cf218f002.jpg'],
];
$gallery = Container::gallery();
$i = 0;
foreach ($portfolio as [$artistName, $url]) {
    $gallery->save([
        'kind' => 'IMAGE',
        'url' => $url,
        'artist_id' => $artistIds[$artistName] ?? null,
        'caption' => '',
        'tags' => ['portfolio'],
        'sort_index' => $i++,
    ]);
}
echo "✓ " . count($portfolio) . " portfolio images seeded\n";

// Note: Wix VOD videos are locked to Wix's player and can't be embedded
// directly. To add real videos to the site, the shop owner should either
// upload MP4 files via /admin/gallery or paste a YouTube/Vimeo URL.

echo "\nDone. Run seed_admin.php next to create the first admin user.\n";
