@@ -23,35 +23,35 @@ import (
2323)
2424
2525type gatheringLineDiff struct {
26- Line entitydiff.Diff [* billing.GatheringLine ]
26+ Line entitydiff.Diff [* billing.UpcomingCharge ]
2727}
2828
29- func diffGatheringInvoiceLines (lines billing.GatheringLines ) (gatheringLineDiff , error ) {
30- dbState := []* billing.GatheringLine {}
29+ func diffGatheringInvoiceLines (lines billing.UpcomingCharges ) (gatheringLineDiff , error ) {
30+ dbState := []* billing.UpcomingCharge {}
3131 for _ , line := range lines {
3232 if line .DBState != nil {
3333 dbState = append (dbState , line .DBState )
3434 }
3535 }
3636
37- linePtrs := lo .Map (lines , func (_ billing.GatheringLine , idx int ) * billing.GatheringLine {
37+ linePtrs := lo .Map (lines , func (_ billing.UpcomingCharge , idx int ) * billing.UpcomingCharge {
3838 return & lines [idx ]
3939 })
4040
4141 diff := gatheringLineDiff {}
4242
43- err := entitydiff .DiffByID (entitydiff.DiffByIDInput [* billing.GatheringLine ]{
43+ err := entitydiff .DiffByID (entitydiff.DiffByIDInput [* billing.UpcomingCharge ]{
4444 DBState : dbState ,
4545 ExpectedState : linePtrs ,
46- HandleDelete : func (item * billing.GatheringLine ) error {
46+ HandleDelete : func (item * billing.UpcomingCharge ) error {
4747 diff .Line .NeedsDelete (item )
4848 return nil
4949 },
50- HandleCreate : func (item * billing.GatheringLine ) error {
50+ HandleCreate : func (item * billing.UpcomingCharge ) error {
5151 diff .Line .NeedsCreate (item )
5252 return nil
5353 },
54- HandleUpdate : func (item entitydiff.DiffUpdate [* billing.GatheringLine ]) error {
54+ HandleUpdate : func (item entitydiff.DiffUpdate [* billing.UpcomingCharge ]) error {
5555 diff .Line .NeedsUpdate (item )
5656 return nil
5757 },
@@ -63,14 +63,14 @@ func diffGatheringInvoiceLines(lines billing.GatheringLines) (gatheringLineDiff,
6363 return diff , nil
6464}
6565
66- func (a * adapter ) updateGatheringLines (ctx context.Context , lines billing.GatheringLines ) error {
66+ func (a * adapter ) updateUpcomingCharges (ctx context.Context , lines billing.UpcomingCharges ) error {
6767 diff , err := diffGatheringInvoiceLines (lines )
6868 if err != nil {
6969 return err
7070 }
7171
72- err = upsertWithOptions (ctx , a .db , diff .Line , upsertInput [* billing.GatheringLine , * db.BillingInvoiceUsageBasedLineConfigCreate ]{
73- Create : func (tx * db.Client , line * billing.GatheringLine ) (* db.BillingInvoiceUsageBasedLineConfigCreate , error ) {
72+ err = upsertWithOptions (ctx , a .db , diff .Line , upsertInput [* billing.UpcomingCharge , * db.BillingInvoiceUsageBasedLineConfigCreate ]{
73+ Create : func (tx * db.Client , line * billing.UpcomingCharge ) (* db.BillingInvoiceUsageBasedLineConfigCreate , error ) {
7474 if line .UBPConfigID == "" {
7575 line .UBPConfigID = ulid .Make ().String ()
7676 }
@@ -97,8 +97,8 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather
9797 return fmt .Errorf ("creating usage based line configs: %w" , err )
9898 }
9999
100- invoiceLineUpsertConfig := upsertInput [* billing.GatheringLine , * db.BillingInvoiceLineCreate ]{
101- Create : func (tx * db.Client , line * billing.GatheringLine ) (* db.BillingInvoiceLineCreate , error ) {
100+ invoiceLineUpsertConfig := upsertInput [* billing.UpcomingCharge , * db.BillingInvoiceLineCreate ]{
101+ Create : func (tx * db.Client , line * billing.UpcomingCharge ) (* db.BillingInvoiceLineCreate , error ) {
102102 if line .ID == "" {
103103 line .ID = ulid .Make ().String ()
104104 }
@@ -162,7 +162,7 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather
162162 UpdateChildUniqueReferenceID ().
163163 Exec (ctx )
164164 },
165- MarkDeleted : func (ctx context.Context , line * billing.GatheringLine ) (* billing.GatheringLine , error ) {
165+ MarkDeleted : func (ctx context.Context , line * billing.UpcomingCharge ) (* billing.UpcomingCharge , error ) {
166166 line .DeletedAt = lo .ToPtr (clock .Now ().In (time .UTC ))
167167 return line , nil
168168 },
@@ -175,24 +175,24 @@ func (a *adapter) updateGatheringLines(ctx context.Context, lines billing.Gather
175175 return nil
176176}
177177
178- func (a * adapter ) mapGatheringInvoiceLinesFromDB (schemaLevel int , dbLines []* db.BillingInvoiceLine ) ([]billing.GatheringLine , error ) {
179- return slicesx .MapWithErr (dbLines , func (dbLine * db.BillingInvoiceLine ) (billing.GatheringLine , error ) {
178+ func (a * adapter ) mapGatheringInvoiceLinesFromDB (schemaLevel int , dbLines []* db.BillingInvoiceLine ) ([]billing.UpcomingCharge , error ) {
179+ return slicesx .MapWithErr (dbLines , func (dbLine * db.BillingInvoiceLine ) (billing.UpcomingCharge , error ) {
180180 return a .mapGatheringInvoiceLineFromDB (schemaLevel , dbLine )
181181 })
182182}
183183
184- func (a * adapter ) mapGatheringInvoiceLineFromDB (schemaLevel int , dbLine * db.BillingInvoiceLine ) (billing.GatheringLine , error ) {
184+ func (a * adapter ) mapGatheringInvoiceLineFromDB (schemaLevel int , dbLine * db.BillingInvoiceLine ) (billing.UpcomingCharge , error ) {
185185 if dbLine .Type != billing .InvoiceLineTypeUsageBased {
186- return billing.GatheringLine {}, fmt .Errorf ("only usage based lines can be gathering invoice lines [line_id=%s]" , dbLine .ID )
186+ return billing.UpcomingCharge {}, fmt .Errorf ("only usage based lines can be gathering invoice lines [line_id=%s]" , dbLine .ID )
187187 }
188188
189189 ubpLine := dbLine .Edges .UsageBasedLine
190190 if ubpLine == nil {
191- return billing.GatheringLine {}, fmt .Errorf ("usage based line data is missing [line_id=%s]" , dbLine .ID )
191+ return billing.UpcomingCharge {}, fmt .Errorf ("usage based line data is missing [line_id=%s]" , dbLine .ID )
192192 }
193193
194- line := billing.GatheringLine {
195- GatheringLineBase : billing.GatheringLineBase {
194+ line := billing.UpcomingCharge {
195+ UpcomingChargeBase : billing.UpcomingChargeBase {
196196 ManagedResource : models .NewManagedResource (models.ManagedResourceInput {
197197 Namespace : dbLine .Namespace ,
198198 ID : dbLine .ID ,
@@ -243,7 +243,7 @@ func (a *adapter) mapGatheringInvoiceLineFromDB(schemaLevel int, dbLine *db.Bill
243243
244244 cloned , err := line .WithoutDBState ()
245245 if err != nil {
246- return billing.GatheringLine {}, fmt .Errorf ("cloning line: %w" , err )
246+ return billing.UpcomingCharge {}, fmt .Errorf ("cloning line: %w" , err )
247247 }
248248
249249 line .DBState = lo .ToPtr (cloned )
0 commit comments