package subscribeplanrepository

import (
	"fmt"
	subscribeplandomain "legalgo-BE-go/internal/domain/subscribe_plan"

	"gorm.io/gorm/clause"
)

func (a *accessor) Update(spec subscribeplandomain.SubscribePlan) error {
	if err := a.db.Clauses(clause.OnConflict{
		Columns: []clause.Column{{Name: "id"}},
		DoUpdates: clause.AssignmentColumns([]string{
			"name",
			"code",
			"length",
			"price",
			"status",
			"updated_at",
		}),
	}).Select(
		"name",
		"code",
		"length",
		"price",
		"status",
		"updated_at",
	).Save(&spec).Error; err != nil {
		return fmt.Errorf("failed to update tag: %v", err)
	}

	return nil
}
