# -*- coding: utf-8 -*-
"""Ejemplo 24: Todas las versiones de DLL (inventario completo)."""

from basskit.dlls.bass import bass
from basskit.dlls.bass_fx import bass_fx
from basskit.dlls.bassmix import bassmix
from basskit.dlls.bassenc import bassenc
from basskit.dlls.bassmidi import bassmidi
from basskit.dlls.basswasapi import basswasapi
from basskit.dlls.addons import bassloud


def ver(v):
	return f"{(v>>24)&0xFF}.{(v>>16)&0xFF}.{(v>>8)&0xFF}.{v&0xFF}"


def main():
	print("=== Inventario completo de DLLs de basskit ===\n")

	dlls = [
		("bass.dll", lambda: bass.BASS_GetVersion()),
		("bass_fx.dll", lambda: bass_fx.BASS_FX_GetVersion()),
		("bassmix.dll", lambda: bassmix.BASS_Mixer_GetVersion()),
		("bassenc.dll", lambda: bassenc.BASS_Encode_GetVersion()),
		("bassmidi.dll", lambda: bassmidi.BASS_MIDI_GetVersion()),
		("basswasapi.dll", lambda: basswasapi.BASS_WASAPI_GetVersion()),
		("bassloud.dll", lambda: bassloud.BASS_Loudness_GetVersion()),
	]

	# Sub-encoders
	sub_enc = []
	try:
		from basskit.dlls.addons import bassenc_flac
		sub_enc.append(("bassenc_flac.dll", lambda: bassenc_flac.BASS_Encode_FLAC_GetVersion()))
	except: pass
	try:
		from basskit.dlls.addons import bassenc_mp3
		sub_enc.append(("bassenc_mp3.dll", lambda: bassenc_mp3.BASS_Encode_MP3_GetVersion()))
	except: pass
	try:
		from basskit.dlls.addons import bassenc_ogg
		sub_enc.append(("bassenc_ogg.dll", lambda: bassenc_ogg.BASS_Encode_OGG_GetVersion()))
	except: pass
	try:
		from basskit.dlls.addons import bassenc_opus
		sub_enc.append(("bassenc_opus.dll", lambda: bassenc_opus.BASS_Encode_OPUS_GetVersion()))
	except: pass

	print(f"{'DLL':<25} {'Version':<15} {'Estado'}")
	print("-" * 50)

	total = 0
	ok = 0
	for nombre, fn in dlls + sub_enc:
		total += 1
		try:
			v = fn()
			print(f"  {nombre:<23} {ver(v):<15} OK")
			ok += 1
		except Exception as e:
			print(f"  {nombre:<23} {'---':<15} ERROR: {e}")

	# Plugins (sin version, solo carga)
	plugins = [
		"bassflac", "bassopus", "basswv", "bassalac", "bassape",
		"bassdsd", "basshls", "basswebm", "bass_aac", "bass_ac3",
		"bass_mpc", "bass_spx", "bass_tta", "bass_ofr",
	]
	print()
	for nombre in plugins:
		total += 1
		try:
			from basskit.cargador import cargar_addon
			d = cargar_addon(nombre)
			if d:
				print(f"  {nombre + '.dll':<23} {'(plugin)':<15} OK")
				ok += 1
			else:
				print(f"  {nombre + '.dll':<23} {'---':<15} NO ENCONTRADA")
		except Exception as e:
			print(f"  {nombre + '.dll':<23} {'---':<15} ERROR")

	print(f"\nTotal: {ok}/{total} DLLs operativas")

	# Info de efectos disponibles
	from basskit.alto_nivel.efectos import CadenaEfectos
	efectos = CadenaEfectos.efectos_disponibles()
	print(f"\nEfectos de audio disponibles: {len(efectos)}")
	for e in efectos:
		print(f"  - {e}")


if __name__ == "__main__":
	main()
