package db

import (
	"context"
	"youngee_b_api/model/gorm_model"
)

func CreateProductPhoto(ctx context.Context, productPhotos []gorm_model.YounggeeProductPhoto) error {
	db := GetReadDB(ctx)
	err := db.Create(&productPhotos).Error
	if err != nil {
		return err
	}
	return nil
}

func GetProductPhotoByProductID(ctx context.Context, productID int64) ([]gorm_model.YounggeeProductPhoto, error) {
	db := GetReadDB(ctx)
	productPhotos := []gorm_model.YounggeeProductPhoto{}
	err := db.Where("product_id = ?", productID).Find(&productPhotos).Error
	if err != nil {
		return nil, err
	}
	return productPhotos, nil
}

func DeleteProductPhotoByProductID(ctx context.Context, productID int64) error {
	db := GetReadDB(ctx)
	err := db.Where("product_id = ?", productID).Delete(&gorm_model.YounggeeProductPhoto{}).Error
	if err != nil {
		return err
	}
	return nil
}

// GetStorePhotoByStoreID 根据门店ID查找门店图片信息
func GetStorePhotoByStoreID(ctx context.Context, storeId int) ([]gorm_model.YounggeeProductPhoto, error) {
	db := GetReadDB(ctx)
	productPhotos := []gorm_model.YounggeeProductPhoto{}
	err := db.Where("store_id = ?", storeId).Find(&productPhotos).Error
	if err != nil {
		return nil, err
	}
	return productPhotos, nil
}
