package store import ( "encoding/json" "task-dashboard/internal/models" ) // SetTaskLabels replaces a task's label set entirely (not an add/remove // single-label API), matching UpdateNativeTask's replace-whole-value style. // Returns ErrNativeTaskNotFound if id doesn't match any row. func (s *Store) SetTaskLabels(id string, labels []string) error { labelsJSON, _ := json.Marshal(labels) result, err := s.db.Exec(` UPDATE native_tasks SET labels = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? `, string(labelsJSON), id) if err != nil { return err } return checkRowsAffected(result) } // GetLabelColors returns every label that has been assigned a color. func (s *Store) GetLabelColors() ([]models.LabelColor, error) { rows, err := s.db.Query(`SELECT name, color FROM labels ORDER BY name ASC`) if err != nil { return nil, err } defer func() { _ = rows.Close() }() var colors []models.LabelColor for rows.Next() { var c models.LabelColor if err := rows.Scan(&c.Name, &c.Color); err != nil { return nil, err } colors = append(colors, c) } return colors, rows.Err() } // SetLabelColor assigns (or reassigns) a label's display color. func (s *Store) SetLabelColor(name, color string) error { _, err := s.db.Exec(`INSERT OR REPLACE INTO labels (name, color) VALUES (?, ?)`, name, color) return err }