<?php
declare(strict_types=1);

namespace App\Repositories;

use App\Json\FileStore;

/**
 * Tiny service container. Swaps repository implementations by config('data_driver').
 * Today: 'json'. Phase 2: 'mysql' — add MysqlXxxRepository classes alongside the
 * existing JsonXxxRepository classes and return them here.
 */
class Container
{
    private static array $instances = [];

    private static function store(string $file): FileStore
    {
        $path = config('data_path') . DIRECTORY_SEPARATOR . $file;
        return self::$instances['store:' . $file] ??= new FileStore($path);
    }

    public static function users(): UserRepository
    {
        return self::$instances['users'] ??= new JsonUserRepository(self::store('users.json'));
    }

    public static function artists(): ArtistRepository
    {
        return self::$instances['artists'] ??= new JsonArtistRepository(self::store('artists.json'));
    }

    public static function schedules(): ScheduleRepository
    {
        return self::$instances['schedules'] ??= new JsonScheduleRepository(self::store('schedules.json'));
    }

    public static function appointments(): AppointmentRepository
    {
        return self::$instances['appointments'] ??= new JsonAppointmentRepository(self::store('appointments.json'));
    }

    public static function intakeForms(): IntakeFormRepository
    {
        return self::$instances['intake'] ??= new JsonIntakeFormRepository(self::store('intake_forms.json'));
    }

    public static function gallery(): GalleryRepository
    {
        return self::$instances['gallery'] ??= new JsonGalleryRepository(self::store('gallery.json'));
    }

    public static function audit(): AuditRepository
    {
        return self::$instances['audit'] ??= new JsonAuditRepository(self::store('audit.json'));
    }

    public static function settings(): SettingsRepository
    {
        return self::$instances['settings'] ??= new JsonSettingsRepository(self::store('settings.json'));
    }
}
