package dao

import (
	"github.com/sirupsen/logrus"
	"youngee_b_api/app/entity"
)

type RewardStrategyDao struct{}

func (d RewardStrategyDao) DeleteRewardStrategyBySelectionId(selectionId string) error {
	err := Db.Where("selection_id = ?", selectionId).Delete(&entity.RewardStrategy{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (d RewardStrategyDao) CreateRewardStrategy(rewardStrategys []entity.RewardStrategy) error {
	err := Db.Create(&rewardStrategys).Error
	if err != nil {
		return err
	}
	return nil
}

func (d RewardStrategyDao) GetRewardStrategyBySelectionId(selectionId string) ([]*entity.RewardStrategy, error) {
	var rewardStrategys []*entity.RewardStrategy
	err := Db.Model(entity.RewardStrategy{}).Where("selection_id = ?", selectionId).Find(&rewardStrategys).Error
	if err != nil {
		logrus.Errorf("[GetRewardStrategyBySelectionId] error query, err:%+v", err)
		return nil, err
	}
	return rewardStrategys, nil
}
