package actions

import (
	"zzman/model"

	"gorm.io/gorm"
)

func FindConfigs(tx *gorm.DB) ([]model.Config, error) {
	var configs []model.Config
	err := tx.Find(&configs).Error
	if err != nil {
		return nil, err
	}
	return configs, nil
}

func UpdateConfigs(tx *gorm.DB, configs []model.ConfigUpdate) error {
	if len(configs) == 0 {
		return nil
	}

	// 批量更新配置
	for _, config := range configs {
		err := tx.
			Where("id = ?", config.Id).
			Updates(&config).
			Error
		if err != nil {
			return err
		}
	}

	return nil
}
