// Copyright (c) 2026 Alibaba Group and its affiliates

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package attestation

import (
	"encoding/json"

	"github.com/dashscope/dashscope-confidential-maas/pkg/transparency"
)

// AttestationBundle packages all data needed for key negotiation.
type AttestationBundle struct {
	TEEType           string            `json:"tee_type"`               // "tdx", "sgx", "sev-snp"
	ServerPublicKey   string            `json:"server_public_key"`      // Server signing public key (PEM)
	EphemeralKeyShare string            `json:"ephemeral_key_share"`    // Ephemeral ECDHE public key (PEM)
	Signature         string            `json:"signature"`              // Ephemeral key signature (base64)
	Evidence          json.RawMessage   `json:"evidence"`               // TEE evidence, schema depends on tee_type
	Transparency      *TransparencyData `json:"transparency,omitempty"` // Transparency log data (optional)
}

// TdxEvidence is the evidence format when tee_type="tdx".
// Aligned with CoCo community TdxEvidence (attestation-agent attester output).
type TdxEvidence struct {
	Quote      string `json:"quote"`       // base64(TDX DCAP Quote)
	CCEventLog string `json:"cc_eventlog"` // base64(CCEL + AAEL)
}

// TransparencyData contains data needed for transparency log verification.
type TransparencyData struct {
	ReleaseManifest transparency.ReleaseManifest `json:"release_manifest"`
	Proofs          []transparency.ProofEntry    `json:"proofs"`
}
