package ucca

import "time"

// =============================================================================
// License Policy Types
// =============================================================================

// LicensedContentFacts represents the license-related facts from the wizard
type LicensedContentFacts struct {
	Present           bool   `json:"present"`
	Publisher         string `json:"publisher"`          // DIN_MEDIA, VDI, VDE, ISO, etc.
	LicenseType       string `json:"license_type"`       // SINGLE_WORKSTATION, NETWORK_INTRANET, etc.
	AIUsePermitted    string `json:"ai_use_permitted"`   // YES, NO, UNKNOWN
	ProofUploaded     bool   `json:"proof_uploaded"`
	OperationMode     string `json:"operation_mode"`     // LINK_ONLY, NOTES_ONLY, FULLTEXT_RAG, TRAINING
	DistributionScope string `json:"distribution_scope"` // SINGLE_USER, COMPANY_INTERNAL, etc.
	ContentType       string `json:"content_type"`       // NORM_FULLTEXT, CUSTOMER_NOTES, etc.
}

// LicensePolicyResult represents the evaluation result
type LicensePolicyResult struct {
	Allowed            bool                `json:"allowed"`
	EffectiveMode      string              `json:"effective_mode"`      // The mode that will actually be used
	Reason             string              `json:"reason"`
	Gaps               []LicenseGap        `json:"gaps"`
	RequiredControls   []LicenseControl    `json:"required_controls"`
	StopLine           *LicenseStopLine    `json:"stop_line,omitempty"` // If hard blocked
	OutputRestrictions *OutputRestrictions `json:"output_restrictions"`
	EscalationLevel    string              `json:"escalation_level"`
	RiskScore          int                 `json:"risk_score"`
}

// LicenseGap represents a license-related gap
type LicenseGap struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Controls    []string `json:"controls"`
	Severity    string   `json:"severity"`
}

// LicenseControl represents a required control for license compliance
type LicenseControl struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	WhatToDo    string   `json:"what_to_do"`
	Evidence    []string `json:"evidence_needed"`
}

// LicenseStopLine represents a hard block
type LicenseStopLine struct {
	ID      string `json:"id"`
	Title   string `json:"title"`
	Message string `json:"message"`
	Outcome string `json:"outcome"` // NOT_ALLOWED, NOT_ALLOWED_UNTIL_LICENSE_CLEARED
}

// OutputRestrictions defines how outputs should be filtered
type OutputRestrictions struct {
	AllowQuotes     bool `json:"allow_quotes"`
	MaxQuoteLength  int  `json:"max_quote_length"` // in characters
	RequireCitation bool `json:"require_citation"`
	AllowCopy       bool `json:"allow_copy"`
	AllowExport     bool `json:"allow_export"`
}

// LicenseIngestDecision represents the decision for ingesting a document
type LicenseIngestDecision struct {
	AllowFulltext bool   `json:"allow_fulltext"`
	AllowNotes    bool   `json:"allow_notes"`
	AllowMetadata bool   `json:"allow_metadata"`
	Reason        string `json:"reason"`
	EffectiveMode string `json:"effective_mode"`
}

// LicenseAuditEntry represents an audit log entry for license decisions
type LicenseAuditEntry struct {
	Timestamp     time.Time             `json:"timestamp"`
	TenantID      string                `json:"tenant_id"`
	DocumentID    string                `json:"document_id,omitempty"`
	Facts         *LicensedContentFacts `json:"facts"`
	Decision      string                `json:"decision"` // ALLOW, DENY, DOWNGRADE
	EffectiveMode string                `json:"effective_mode"`
	Reason        string                `json:"reason"`
	StopLineID    string                `json:"stop_line_id,omitempty"`
}
