package clause

type OnConflict struct {
	Columns      []Column
	Where        Where
	TargetWhere  Where
	OnConstraint string
	DoNothing    bool
	DoUpdates    Set
	UpdateAll    bool
}

func (OnConflict) () string {
	return "ON CONFLICT"
}

// Build build onConflict clause
func ( OnConflict) ( Builder) {
	if .OnConstraint != "" {
		.WriteString("ON CONSTRAINT ")
		.WriteString(.OnConstraint)
		.WriteByte(' ')
	} else {
		if len(.Columns) > 0 {
			.WriteByte('(')
			for ,  := range .Columns {
				if  > 0 {
					.WriteByte(',')
				}
				.WriteQuoted()
			}
			.WriteString(`) `)
		}

		if len(.TargetWhere.Exprs) > 0 {
			.WriteString(" WHERE ")
			.TargetWhere.Build()
			.WriteByte(' ')
		}
	}

	if .DoNothing {
		.WriteString("DO NOTHING")
	} else {
		.WriteString("DO UPDATE SET ")
		.DoUpdates.Build()
	}

	if len(.Where.Exprs) > 0 {
		.WriteString(" WHERE ")
		.Where.Build()
		.WriteByte(' ')
	}
}

// MergeClause merge onConflict clauses
func ( OnConflict) ( *Clause) {
	.Expression = 
}