package dao

type UserCharacter struct {
	ID          int32  `gorm:"primaryKey;type:int;not null;auto_increment;comment:'角色ID'"`
	UserId      int32  `gorm:"default null;comment:'关联的用户ID'"`
	CharacterId int32  `gorm:"default null;comment:'关联的角色ID'"`
	Persona     string `gorm:"type:json;default null;comment:'个性化配置'"`
}

// 根据userId，查询关联的角色表
func UserCharacter_QueryList(userId int32) ([]*UserCharacter, error) {
	var list []*UserCharacter
	if err := s.db.Where("user_id = ?", userId).Find(&list).Error; err != nil {
		return nil, err
	}
	return list, nil
}

// 根据userId，查询关联角色的role_id
func UserCharacter_QueryList_OnlyCharacterId(userId int32) ([]int32, error) {
	var list []int32
	if err := s.db.Model(&UserCharacter{}).Where("user_id = ?", userId).Select("character_id").Scan(&list).Error; err != nil {
		return nil, err
	}
	return list, nil
}
