package activity

import (
	"context"

	"bindbox-game/internal/repository/mysql/dao"
	"bindbox-game/internal/repository/mysql/model"
)

// CreateIssueRewards 批量创建期奖励
// 参数: issueID 期ID, rewards 奖励创建输入数组
// 返回: 错误信息
func (s *service) CreateIssueRewards(ctx context.Context, issueID int64, rewards []CreateRewardInput) error {
	return s.writeDB.Transaction(func(tx *dao.Query) error {
		for _, r := range rewards {
			item := &model.ActivityRewardSettings{
				IssueID:     issueID,
				ProductID:   r.ProductID,
				Weight:      r.Weight,
				Quantity:    r.Quantity,
				OriginalQty: r.OriginalQty,
				Level:       r.Level,
				Sort:        r.Sort,
				IsBoss:      r.IsBoss,
				MinScore:    r.MinScore,
			}
			if err := tx.ActivityRewardSettings.WithContext(ctx).Create(item); err != nil {
				return err
			}
		}
		return nil
	})
}
