<?php
declare(strict_types=1);

namespace App\Repositories;

use App\Json\FileStore;

class JsonSettingsRepository implements SettingsRepository
{
    public function __construct(private FileStore $store) {}

    public function get(): array
    {
        $d = $this->store->read();
        return $d ?: self::defaults();
    }

    public function save(array $settings): array
    {
        $merged = array_merge(self::defaults(), $this->store->read() ?: [], $settings);
        $this->store->write($merged);
        return $merged;
    }

    public static function defaults(): array
    {
        return [
            'shop_name'  => 'Mystic Art Tattoo',
            'tagline_en' => 'Fine-line, realism, lettering and custom work.',
            'tagline_es' => 'Líneas finas, realismo, lettering y trabajos personalizados.',
            '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',
            ],
            'address' => '179 US-46 #16, Rockaway, NJ 07866',
            'phone'   => '862-596-6098',
            'email'   => 'info@mysticartatto.com',
            'socials' => [
                'instagram' => 'https://www.instagram.com/mysticarttatto',
                'facebook'  => '',
                'tiktok'    => '',
                'whatsapp'  => '',
            ],
            'map_embed_url' => 'https://www.google.com/maps/embed/v1/place?key=&q=179+US-46+Rockaway+NJ+07866',
            'updated_at' => now_iso(),
        ];
    }
}
