package assets

import (
	"gitea.boner.be/bdnugget/goonscape/types"
	rl "github.com/gen2brain/raylib-go/raylib"
)

func LoadModels() ([]types.ModelAsset, error) {
	goonerModel := rl.LoadModel("resources/models/goonion.obj")
	goonerTexture := rl.LoadTexture("resources/models/goonion.png")
	rl.SetMaterialTexture(goonerModel.Materials, rl.MapDiffuse, goonerTexture)

	coomerModel := rl.LoadModel("resources/models/coomer.obj")
	coomerTexture := rl.LoadTexture("resources/models/coomer.png")
	rl.SetMaterialTexture(coomerModel.Materials, rl.MapDiffuse, coomerTexture)

	shrekeModel := rl.LoadModel("resources/models/shreke.obj")
	shrekeTexture := rl.LoadTexture("resources/models/shreke.png")
	rl.SetMaterialTexture(shrekeModel.Materials, rl.MapDiffuse, shrekeTexture)

	return []types.ModelAsset{
		{Model: goonerModel, Texture: goonerTexture},
		{Model: coomerModel, Texture: coomerTexture},
		{Model: shrekeModel, Texture: shrekeTexture},
	}, nil
}

func LoadMusic(filename string) (rl.Music, error) {
	return rl.LoadMusicStream(filename), nil
}

func UnloadModels(models []types.ModelAsset) {
	for _, model := range models {
		rl.UnloadModel(model.Model)
		rl.UnloadTexture(model.Texture)
	}
}

func UnloadMusic(music rl.Music) {
	rl.UnloadMusicStream(music)
}
