// Filename: internal/db/mysql_adapter.go
package dialect

import (
	"gorm.io/gorm"
	"gorm.io/gorm/clause"
)

type mysqlAdapter struct{}

func NewMySQLAdapter() DialectAdapter {
	return &mysqlAdapter{}
}

func (a *mysqlAdapter) OnConflictUpdateAll(conflictColumns []string, updateColumns []string) clause.Expression {
	conflictCols := make([]clause.Column, len(conflictColumns))
	for i, col := range conflictColumns {
		conflictCols[i] = clause.Column{Name: col}
	}

	assignments := make(map[string]interface{})
	for _, col := range updateColumns {
		assignments[col] = gorm.Expr(col + " + VALUES(" + col + ")")
	}

	return clause.OnConflict{
		Columns:   conflictCols,
		DoUpdates: clause.Assignments(assignments),
	}
}
