package dao

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

type SecMaterialDao struct{}

func (d SecMaterialDao) DeleteSecMaterialBySelectionId(selectionId string) error {
	err := Db.Where("selection_id = ?", selectionId).Delete(entity.SecMaterial{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (d SecMaterialDao) CreateSecMaterial(secExample entity.SecMaterial) error {
	err := Db.Create(&secExample).Error
	if err != nil {
		return err
	}
	return nil
}

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