package dao

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

type FreeStrategyDao struct{}

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

func (d FreeStrategyDao) CreateFreeStrategy(freeStrategys []entity.FreeStrategy) error {
	err := Db.Create(&freeStrategys).Error
	if err != nil {
		return err
	}
	return nil
}

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