// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package worker

import (
	"context"

	"golang.org/x/vulndb/internal/derrors"
	"golang.org/x/vulndb/internal/observe"
	"golang.org/x/vulndb/internal/worker/store"
)

// updateFalsePositives makes sure the store reflects the list of false positives.
func updateFalsePositives(ctx context.Context, st store.Store) (err error) {
	defer derrors.Wrap(&err, "updateFalsePositives")
	ctx, span := observe.Start(ctx, "updateFalsePositives")
	defer span.End()

	for i := 0; i < len(falsePositives); i += maxTransactionWrites {
		j := i + maxTransactionWrites
		if j >= len(falsePositives) {
			j = len(falsePositives)
		}
		batch := falsePositives[i:j]
		err := st.RunTransaction(ctx, func(ctx context.Context, tx store.Transaction) error {
			oldRecords, err := readCVE4Records(tx, batch)
			if err != nil {
				return err
			}
			for i, cr := range batch {
				old := oldRecords[i]
				var err error
				if old == nil {
					err = tx.CreateRecord(cr)
				} else if old.CommitHash != cr.CommitHash && !old.CommitTime.IsZero() && old.CommitTime.Before(cr.CommitTime) {
					// If the false positive data is more recent than what is in
					// the store, then update the DB. But ignore records whose
					// commit time hasn't been populated.
					err = tx.SetRecord(cr)
				}
				if err != nil {
					return err
				}
			}
			return nil
		})
		if err != nil {
			return err
		}
	}
	return nil
}

func readCVE4Records(tx store.Transaction, crs []*store.CVE4Record) ([]*store.CVE4Record, error) {
	var olds []*store.CVE4Record
	for _, cr := range crs {
		dbcrs, err := tx.GetCVE4Records(cr.ID, cr.ID)
		if err != nil {
			return nil, err
		}
		var old *store.CVE4Record
		if len(dbcrs) > 0 {
			old = dbcrs[0]
		}
		olds = append(olds, old)
	}
	return olds, nil
}
