package subscriberepository

import (
	"fmt"
	subscribedomain "legalgo-BE-go/internal/domain/subscribe"

	"gorm.io/gorm/clause"
)

func (a *accessor) Update(spec subscribedomain.Subscribe) error {
	if err := a.db.Clauses(clause.OnConflict{
		Columns:   []clause.Column{{Name: "id"}},
		DoUpdates: clause.AssignmentColumns([]string{"status", "subscribe_plan_id", "start_date"}),
	}).Create(&spec).Error; err != nil {
		return fmt.Errorf("failed to update status: %v", err)
	}

	return nil
}
