package store import ( "context" "time" "github.com/google/uuid" "github.com/jmoiron/sqlx" "git.hangman-lab.top/hzhang/Dialectic.Backend/internal/models" ) type Argument struct { ID string `db:"id" json:"id"` TopicID string `db:"topic_id" json:"topic_id"` RoundID string `db:"round_id" json:"round_id"` Camp models.Camp `db:"camp" json:"camp"` AgentID string `db:"agent_id" json:"agent_id"` Content string `db:"content" json:"content"` PostedAt time.Time `db:"posted_at" json:"posted_at"` } type ArgumentStore struct { db *sqlx.DB } func NewArgumentStore(db *sqlx.DB) *ArgumentStore { return &ArgumentStore{db: db} } type PostArgumentInput struct { TopicID string RoundID string Camp models.Camp AgentID string Content string } func (s *ArgumentStore) Post(ctx context.Context, in PostArgumentInput) (*Argument, error) { id := uuid.NewString() if _, err := s.db.ExecContext(ctx, `INSERT INTO arguments (id, topic_id, round_id, camp, agent_id, content) VALUES (?, ?, ?, ?, ?, ?)`, id, in.TopicID, in.RoundID, in.Camp, in.AgentID, in.Content); err != nil { return nil, err } var a Argument if err := s.db.GetContext(ctx, &a, `SELECT * FROM arguments WHERE id = ?`, id); err != nil { return nil, err } return &a, nil } // ListByTopic returns the full transcript in posted order. Used by the // judge agent at end-of-debate to write the verdict, by the frontend // to render, and by observer agents querying via plugin. func (s *ArgumentStore) ListByTopic(ctx context.Context, topicID string) ([]Argument, error) { var rows []Argument if err := s.db.SelectContext(ctx, &rows, `SELECT * FROM arguments WHERE topic_id = ? ORDER BY posted_at ASC, id ASC`, topicID); err != nil { return nil, err } return rows, nil }