package dao

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

type SecBriefDao struct{}

func (p SecBriefDao) DeleteSecBriefBySelectionId(selectionId string) error {
	err := Db.Where("selection_id = ?", selectionId).Delete(entity.SecBrief{}).Error
	if err != nil {
		return err
	}
	return nil
}

func (p SecBriefDao) CreateSecBrief(briefInfo entity.SecBrief) error {
	err := Db.Create(&briefInfo).Error
	if err != nil {
		return err
	}
	return nil
}

func (p SecBriefDao) GetSelectionBriefInfo(selectionId string) ([]*entity.SecBrief, error) {
	var selectionBriefInfos []*entity.SecBrief
	err := Db.Model(entity.SecBrief{}).Where("selection_id = ?", selectionId).Find(&selectionBriefInfos).Error
	if err != nil {
		logrus.Errorf("[GetSelectionBriefInfo] error query mysql, err:%+v", err)
		return nil, err
	}
	return selectionBriefInfos, nil
}
