// Package sync supports the Flutter delta-sync endpoint by writing an
// append-only library_changes log alongside every mutation on tracked
// entities (artists, albums, tracks, likes, playlists, playlist_tracks).
//
// Callers MUST pass the same transaction that performed the underlying
// mutation — the change row and the mutation must commit or roll back
// together. See LogChange in changes.go.
package sync

// EntityType enumerates the entity kinds whose mutations are tracked
// by the library_changes log. Values must stay in sync with the CHECK
// constraint on library_changes.entity_type (migration 0025).
type EntityType string

const (
	EntityArtist        EntityType = "artist"
	EntityAlbum         EntityType = "album"
	EntityTrack         EntityType = "track"
	EntityLikeTrack     EntityType = "like_track"
	EntityLikeAlbum     EntityType = "like_album"
	EntityLikeArtist    EntityType = "like_artist"
	EntityPlaylist      EntityType = "playlist"
	EntityPlaylistTrack EntityType = "playlist_track"
)

// Op is upsert or delete. Matches the CHECK constraint in migration 0025.
type Op string

const (
	OpUpsert Op = "upsert"
	OpDelete Op = "delete"
)

// Change is the wire shape returned by the sync endpoint to clients.
type Change struct {
	ID         int64      `json:"id"`
	EntityType EntityType `json:"entity_type"`
	EntityID   string     `json:"entity_id"`
	Op         Op         `json:"op"`
}
