package repository

import (
	"web-qudo-be/app/database"
	"web-qudo-be/app/database/entity"
)

type popupNewsContentImagesRepository struct {
	DB *database.Database
}

type PopupNewsContentImagesRepository interface {
	Create(data *entity.PopupNewsContentImages) error
	Delete(id uint) error

	// 🔥 optional tapi recommended
	ResetThumbnail(popupNewsContentID uint) error
}

func NewPopupNewsContentImagesRepository(db *database.Database) PopupNewsContentImagesRepository {
	return &popupNewsContentImagesRepository{
		DB: db,
	}
}

// Create
func (_i *popupNewsContentImagesRepository) Create(data *entity.PopupNewsContentImages) error {
	return _i.DB.DB.Create(data).Error
}

// Delete
func (_i *popupNewsContentImagesRepository) Delete(id uint) error {
	return _i.DB.DB.Delete(&entity.PopupNewsContentImages{}, id).Error
}

// 🔥 Reset semua thumbnail jadi false (BEST PRACTICE)
func (_i *popupNewsContentImagesRepository) ResetThumbnail(popupNewsContentID uint) error {
	return _i.DB.DB.Model(&entity.PopupNewsContentImages{}).
		Where("popup_news_content_id = ?", popupNewsContentID).
		Update("is_thumbnail", false).Error
}