package models

import (
	"errors"
	"github.com/go-xorm/xorm"
)

type WorldAsset struct {
	WorldID   int64  `xorm:"'world_id' pk" json:"worldId"` // 世界ID (Primary Key)
	WorldName string `xorm:"world_name" json:"worldName"`
	//VoiceGroups map[string]interface{} `xorm:"'voice_groups' json" json:"voiceGroups" ` // 声线组 (Array of strings)
	VoiceGroups []string `xorm:"'voice_groups' json" json:"voiceGroups" `
	WorldLines  []string `xorm:"'world_lines' json" json:"worldLines" ` // 世界线 (Array of strings)
	WorldRules  string   `xorm:"'world_rules' text" json:"worldRules"`  // 世界规则 (Code Text)
	CreatedAt   int64    `xorm:"'created_at' created" json:"createdAt"` // 创建时间, with `created` tag to auto generate timestamp
	UpdatedAt   int64    `xorm:"'updated_at' updated" json:"updatedAt"` // 更新时间, with `updated` tag to auto generate timestamp
}

// createAsset 创建新的数字人资产
func CreateWorldAsset(session *xorm.Session, asset *WorldAsset) error {
	_, err := session.Insert(asset)
	if err != nil {
		return errors.New("创建世界资产对象失败! ")
	}
	return nil
}

// UpdateWorldAsset 函数用来更新世界资产信息
func UpdateWorldAsset(session *xorm.Session, WorldID int64, asset *WorldAsset) error {
	_, err := session.Where("world_id = ?", WorldID).Update(asset)
	if err != nil {
		return err
	}

	return nil
}
