get()->map(function ($branch) { return [ 'id' => $branch->id, 'branch_name' => $branch->name, 'enable' => $branch->enable, 'rooms' => $branch->rooms ->filter(fn($room) => $room->type === RoomType::PC) ->mapWithKeys(function ($room) { $roomName = ($room->type?->value ?? '') . $room->name; return [ $roomName => [ 'is_online' => $room->is_online, 'status' => $room->status?->value ?? null, 'started_at' => $room->started_at, 'ended_at' => $room->ended_at, ] ]; }), ]; }); return ApiResponse::success(['branches' => $branches]); } }