package book

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/book"
	bookReq "github.com/flipped-aurora/gin-vue-admin/server/model/book/request"
	commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
)

type BookCommentLikeRecordService struct{}

func (s *BookCommentLikeRecordService) CreateBookCommentLikeRecord(item book.BookCommentLikeRecord) error {
	return global.GVA_DB.Create(&item).Error
}

func (s *BookCommentLikeRecordService) DeleteBookCommentLikeRecord(item book.BookCommentLikeRecord) error {
	return global.GVA_DB.Delete(&item).Error
}

func (s *BookCommentLikeRecordService) DeleteBookCommentLikeRecordByIds(ids commonReq.IdsReq) error {
	return deleteByIDs[book.BookCommentLikeRecord](ids.Ids)
}

func (s *BookCommentLikeRecordService) UpdateBookCommentLikeRecord(item book.BookCommentLikeRecord) error {
	return global.GVA_DB.Save(&item).Error
}

func (s *BookCommentLikeRecordService) GetBookCommentLikeRecord(id uint) (item book.BookCommentLikeRecord, err error) {
	err = global.GVA_DB.Where("id = ?", id).First(&item).Error
	return
}

func (s *BookCommentLikeRecordService) GetBookCommentLikeRecordInfoList(info bookReq.BookCommentLikeRecordSearch) (list []book.BookCommentLikeRecord, total int64, err error) {
	db := global.GVA_DB.Model(&book.BookCommentLikeRecord{})
	if info.CommentID != nil {
		db = db.Where("comment_id = ?", *info.CommentID)
	}
	if info.MemberUserID != nil {
		db = db.Where("member_user_id = ?", *info.MemberUserID)
	}
	err = db.Count(&total).Error
	if err != nil {
		return
	}
	err = db.Scopes(paginate(info.PageInfo)).Order("id desc").Find(&list).Error
	return
}
