package graph
import (
"time"
"sourcecraft.dev/bigbes/sr-ht-spec/graph/model"
"sourcecraft.dev/bigbes/sr-ht-spec/service"
)
// NewProposalEvent builds the webhook payload for a proposal lifecycle event.
// The cmd webhook sink calls it; it lives here because converting a
// service.Proposal to the GraphQL model.Proposal is this package's job.
//
// It composes the two existing conversions this package already owns: a
// service.Proposal is field-for-field a graph.Proposal (the same shape
// serviceProposals.ListProposals produces), and proposalModel maps a
// graph.Proposal to the *model.Proposal every GraphQL surface returns. Reusing
// them keeps the webhook payload identical to what a `proposals` query would
// serve for the same proposal.
func NewProposalEvent(event model.WebhookEvent, uuid string, date time.Time, p service.Proposal) (*model.ProposalEvent, error) {
pm, err := proposalModel(Proposal{
ID: p.ID,
Space: p.Space,
Title: p.Title,
Rationale: p.Rationale,
BaseRev: p.BaseRev,
Branch: p.Branch,
State: p.State,
Approval: p.Approval,
MergedRev: p.MergedRev,
Agent: p.Agent,
AgentSession: p.AgentSession,
Created: p.Created,
Resolved: p.Resolved,
})
if err != nil {
return nil, err
}
return &model.ProposalEvent{
UUID: uuid,
Event: event,
Date: date,
Proposal: pm,
}, nil
}