package dao

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

type SelectionReviewDao struct{}

func (p SelectionReviewDao) Create(reviewInfo *entity.ReviewSelection) error {
	err := Db.Create(&reviewInfo).Error
	if err != nil {
		return err
	}
	return nil
}

func (p SelectionReviewDao) GetSelectionReviewByStatus(status int64) ([]*entity.ReviewSelection, error) {
	var reviewSelections []*entity.ReviewSelection
	err := Db.Model(entity.ReviewSelection{}).Where("status = ?", status).Find(&reviewSelections).Error
	if err != nil {
		logrus.Errorf("[GetSelectionReviewByStatus] error query mysql, err:%+v", err)
		return nil, err
	}
	return reviewSelections, nil
}

func (p SelectionReviewDao) UpdateSelectionReview(reviewSelection *entity.ReviewSelection) error {
	err := Db.Debug().Model(&entity.ReviewSelection{}).Where("id = ?", reviewSelection.ID).Updates(reviewSelection).Error
	if err != nil {
		return err
	}
	return nil
}
