package main

import (
	"context"
	"github.com/carlosframework/docs/internal/docs"
	"github.com/carlosframework/docs/internal/docs/linkstore"
	p "github.com/carlosframework/docs/internal/docs/principalstore"
	"amadan.net/rastrillo/rastrillo/db"
	"amadan.net/rastrillo/rastrillo/migrate"
)

// openProbeDB lives in the step file because the old and new trees import
// rastrillo's db from different module paths.
func openProbeDB(path string) (*db.DB, error) { return db.Open(path, nil) }

func principalStep(ctx context.Context, d *db.DB, phase string) int64 {
	_, e := migrate.Apply(ctx, d, migrate.Merge(linkstore.Schema, p.Schema))
	must(e)
	s, e := p.New(d.Writer(), p.Config{Issuer: "https://id.oficina.works", Team: "A1", RequireMembership: func(context.Context, p.MembershipRequest) error { return nil }})
	must(e)
	v, e := s.EnsureHome(ctx, p.HomeIdentity{Issuer: "https://id.oficina.works", Subject: "synthetic-member"})
	must(e)
	if v.VerifiedAddress != nil {
		panic("invented address")
	}
	return v.ID
}

func fixtureActor(id int64, address string) docs.Actor {
	return docs.Actor{PersonID: id, VerifiedAddress: &address}
}
