package adsrepository

import (
	"fmt"
	adsdomain "legalgo-BE-go/internal/domain/ads"

	"gorm.io/gorm/clause"
)

func (a *accessor) Update(spec adsdomain.Ads) error {
	if err := a.db.Clauses(clause.OnConflict{
		Columns: []clause.Column{{Name: "id"}},
		DoUpdates: clause.AssignmentColumns([]string{
			"image_url",
			"url",
			"updated_at",
			"start_date",
			"end_date",
		}),
	}).Select(
		"image_url",
		"url",
		"updated_at",
		"start_date",
		"end_date",
	).Save(&spec).Error; err != nil {
		return fmt.Errorf("failed to update tag: %v", err)
	}

	return nil
}
