private function totalMediaTypeQuery(string $type): int
    {
        if (($type !== self::MEDIA_TYPE_ALL)
            && ($type !== self::MEDIA_TYPE_UNKNOWN)
            && !in_array($type, self::MEDIA_TYPES, true)
        ) {
            return 0;
        }

        $query = DB::table('media')
            ->where('m_file', '=', $this->tree->id());

        if ($type !== self::MEDIA_TYPE_ALL) {
            if ($type === self::MEDIA_TYPE_UNKNOWN) {
                // There has to be a better way then this :(
                foreach (self::MEDIA_TYPES as $t) {
                    // Use function to add brackets
                    $query->where(static function (Builder $query) use ($t): void {
                        $query->where('m_gedcom', 'not like', '%3 TYPE ' . $t . '%')
                            ->where('m_gedcom', 'not like', '%1 _TYPE ' . $t . '%');
                    });
                }
            } else {
                // Use function to add brackets
                $query->where(static function (Builder $query) use ($type): void {
                    $query->where('m_gedcom', 'like', '%3 TYPE ' . $type . '%')
                        ->orWhere('m_gedcom', 'like', '%1 _TYPE ' . $type . '%');
                });
            }
        }

        return $query->count();
    }