package layoutbundleownerverificationv1

import "github.com/pingcap-inc/nexuscrm-contract/pkg/layoutbundlekeyv1"

const (
	ReceiptVersion    = "nexuscrm.layout-bundle-owner-verification-receipt/v1"
	ReceiptSetVersion = "nexuscrm.layout-bundle-owner-verification-receipt-set/v1"

	AppAuthorityEvidenceVersion    = "nexuscrm.layout-bundle-app-authority-evidence/v1"
	TenantAuthorityEvidenceVersion = "nexuscrm.layout-bundle-tenant-authority-evidence/v1"
	SystemAuthorityEvidenceVersion = "nexuscrm.layout-bundle-system-authority-evidence/v1"

	MaxReceipts                 = 100_000
	MaxCanonicalReceiptSetBytes = 32_505_856
)

// VerificationState is a closed canonical tag. V1 admits only VERIFIED.
type VerificationState byte

const (
	VerificationStateVerified VerificationState = 0x01
)

// Receipt is the complete immutable success value for one exact
// BundleAuthorityEvidence reference and one exact live Catalog source
// reservation. Every member is required.
type Receipt struct {
	ReceiptVersion              string
	OrgID                       string
	WriterCommandID             string
	WriterReservationGeneration uint64
	SourceRequestDigest         string
	RequiredBundleKeySetDigest  string
	BundleKey                   layoutbundlekeyv1.BundleKey
	EvidenceVersion             string
	EvidenceDigest              string
	VerificationState           VerificationState
}

// ReceiptEntry is the per-BundleKey projection stored in a ReceiptSet. The
// complete singular Receipt is reconstructed from the set's shared envelope.
type ReceiptEntry struct {
	BundleKey         layoutbundlekeyv1.BundleKey
	EvidenceVersion   string
	EvidenceDigest    string
	VerificationState VerificationState
}

// ReceiptSet is the complete immutable candidate receipt collection. Receipts
// must be present even when empty; input order is not semantic.
type ReceiptSet struct {
	ReceiptSetVersion           string
	ReceiptVersion              string
	OrgID                       string
	WriterCommandID             string
	WriterReservationGeneration uint64
	SourceRequestDigest         string
	RequiredBundleKeySetDigest  string
	Receipts                    []ReceiptEntry
}
