<?php
declare(strict_types=1);
$dir = __DIR__ . '/assets/img/shop/bottles';
@mkdir($dir, 0755, true);
$stock = [
    'kasni'    => 'https://images.unsplash.com/photo-1462143338528-eca9936a4d38?w=800&q=85',
    'naana'    => 'https://images.unsplash.com/photo-1628556270448-4f4e7c80d98b?w=800&q=85',
    'nastaran' => 'https://images.unsplash.com/photo-1525313346988-1fcc206374f0?w=800&q=85',
    'bahar'    => 'https://images.unsplash.com/photo-1550837810-b53c6815fe29?w=800&q=85',
];
$ctx = stream_context_create(['http' => ['timeout' => 30, 'user_agent' => 'Mozilla/5.0 ACC-Shop']]);
$out = [];
foreach ($stock as $slug => $url) {
    $local = $dir . '/' . $slug . '.jpg';
    if (file_exists($local) && filesize($local) > 1000) {
        $out[$slug] = 'exists';
        continue;
    }
    $bin = @file_get_contents($url, false, $ctx);
    if ($bin && strlen($bin) > 1000) {
        file_put_contents($local, $bin);
        $out[$slug] = 'ok';
    } else {
        $out[$slug] = 'fail';
    }
}
$poster = __DIR__ . '/assets/img/shop/hero-poster.jpg';
@mkdir(dirname($poster), 0755, true);
if (!file_exists($poster) || filesize($poster) < 1000) {
    $bin = @file_get_contents('https://images.unsplash.com/photo-1501004318643-1d4f64f7b8a0?w=1920&q=85', false, $ctx);
    $out['poster'] = ($bin && file_put_contents($poster, $bin)) ? 'ok' : 'fail';
}
$video = __DIR__ . '/assets/video/shop-hero.mp4';
@mkdir(dirname($video), 0755, true);
if (!file_exists($video) || filesize($video) < 50000) {
    $bin = @file_get_contents('https://assets.mixkit.co/videos/preview/mixkit-green-plant-leaves-in-the-breeze-9976-large.mp4', false, $ctx);
    $out['video'] = ($bin && strlen($bin) > 50000 && file_put_contents($video, $bin)) ? 'ok' : 'fail';
}
echo json_encode($out, JSON_PRETTY_PRINT);
