<?php

namespace App\Domains\Admin\Controllers;

use App\Models\Tenant;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class TenantListApiController extends CommonController
{
    public function __invoke(Request $request): JsonResponse
    {
        $tenants = Tenant::where('has_active_instance', true)->get()->map(function ($tenant) {
            return [
                'name' => $tenant->name,
                'slug' => $tenant->slug,
                'url' => $tenant->url,
                'is_active_local_group' => $tenant->is_active_local_group,
            ];
        });

        return response()->json(['tenants' => $tenants]);
    }
}
