package ucca

// ============================================================================
// Financial Regulations Policy Engine — Types
// ============================================================================

// DefaultFinancialPolicyPath is the default location for the financial policy file
var DefaultFinancialPolicyPath = "policies/financial_regulations_policy.yaml"

// FinancialPolicyConfig represents the financial regulations policy structure
type FinancialPolicyConfig struct {
	Metadata           FinancialPolicyMetadata        `yaml:"metadata"`
	ApplicableDomains  []string                       `yaml:"applicable_domains"`
	FactsSchema        map[string]interface{}         `yaml:"facts_schema"`
	Controls           map[string]FinancialControlDef `yaml:"controls"`
	Gaps               map[string]FinancialGapDef     `yaml:"gaps"`
	StopLines          map[string]FinancialStopLine   `yaml:"stop_lines"`
	Rules              []FinancialRuleDef             `yaml:"rules"`
	EscalationTriggers []FinancialEscalationTrigger   `yaml:"escalation_triggers"`
}

// FinancialPolicyMetadata contains policy header information
type FinancialPolicyMetadata struct {
	Version       string                    `yaml:"version"`
	EffectiveDate string                    `yaml:"effective_date"`
	Author        string                    `yaml:"author"`
	Jurisdiction  string                    `yaml:"jurisdiction"`
	Regulations   []FinancialRegulationInfo `yaml:"regulations"`
}

// FinancialRegulationInfo describes a regulation
type FinancialRegulationInfo struct {
	Name      string `yaml:"name"`
	FullName  string `yaml:"full_name"`
	Reference string `yaml:"reference,omitempty"`
	Authority string `yaml:"authority,omitempty"`
	Version   string `yaml:"version,omitempty"`
	Effective string `yaml:"effective,omitempty"`
}

// FinancialControlDef represents a control specific to financial regulations
type FinancialControlDef struct {
	ID             string   `yaml:"id"`
	Title          string   `yaml:"title"`
	Category       string   `yaml:"category"`
	DORARef        string   `yaml:"dora_ref,omitempty"`
	MaRiskRef      string   `yaml:"marisk_ref,omitempty"`
	BAITRef        string   `yaml:"bait_ref,omitempty"`
	MiFIDRef       string   `yaml:"mifid_ref,omitempty"`
	GwGRef         string   `yaml:"gwg_ref,omitempty"`
	Description    string   `yaml:"description"`
	WhenApplicable []string `yaml:"when_applicable,omitempty"`
	WhatToDo       string   `yaml:"what_to_do"`
	EvidenceNeeded []string `yaml:"evidence_needed,omitempty"`
	Effort         string   `yaml:"effort"`
}

// FinancialGapDef represents a compliance gap
type FinancialGapDef struct {
	ID          string   `yaml:"id"`
	Title       string   `yaml:"title"`
	Description string   `yaml:"description"`
	Severity    string   `yaml:"severity"`
	Escalation  string   `yaml:"escalation,omitempty"`
	When        []string `yaml:"when,omitempty"`
	Controls    []string `yaml:"controls,omitempty"`
	LegalRefs   []string `yaml:"legal_refs,omitempty"`
}

// FinancialStopLine represents a hard blocker
type FinancialStopLine struct {
	ID          string   `yaml:"id"`
	Title       string   `yaml:"title"`
	Description string   `yaml:"description"`
	Outcome     string   `yaml:"outcome"`
	When        []string `yaml:"when,omitempty"`
	Message     string   `yaml:"message"`
}

// FinancialRuleDef represents a rule from the financial policy
type FinancialRuleDef struct {
	ID          string                `yaml:"id"`
	Category    string                `yaml:"category"`
	Title       string                `yaml:"title"`
	Description string                `yaml:"description"`
	Condition   FinancialConditionDef `yaml:"condition"`
	Effect      FinancialEffectDef    `yaml:"effect"`
	Severity    string                `yaml:"severity"`
	DORARef     string                `yaml:"dora_ref,omitempty"`
	MaRiskRef   string                `yaml:"marisk_ref,omitempty"`
	BAITRef     string                `yaml:"bait_ref,omitempty"`
	MiFIDRef    string                `yaml:"mifid_ref,omitempty"`
	GwGRef      string                `yaml:"gwg_ref,omitempty"`
	Rationale   string                `yaml:"rationale"`
}

// FinancialConditionDef represents a rule condition
type FinancialConditionDef struct {
	Field    string                  `yaml:"field,omitempty"`
	Operator string                  `yaml:"operator,omitempty"`
	Value    interface{}             `yaml:"value,omitempty"`
	AllOf    []FinancialConditionDef `yaml:"all_of,omitempty"`
	AnyOf    []FinancialConditionDef `yaml:"any_of,omitempty"`
}

// FinancialEffectDef represents the effect when a rule triggers
type FinancialEffectDef struct {
	Feasibility string   `yaml:"feasibility,omitempty"`
	ControlsAdd []string `yaml:"controls_add,omitempty"`
	RiskAdd     int      `yaml:"risk_add,omitempty"`
	Escalation  bool     `yaml:"escalation,omitempty"`
}

// FinancialEscalationTrigger defines when to escalate
type FinancialEscalationTrigger struct {
	ID      string   `yaml:"id"`
	Trigger []string `yaml:"trigger,omitempty"`
	Level   string   `yaml:"level"`
	Reason  string   `yaml:"reason"`
}

// ============================================================================
// Financial Assessment Result Types
// ============================================================================

// FinancialAssessmentResult represents the result of financial regulation evaluation
type FinancialAssessmentResult struct {
	IsApplicable     bool                       `json:"is_applicable"`
	MissingContext   bool                       `json:"missing_context,omitempty"`
	Feasibility      Feasibility                `json:"feasibility"`
	RiskScore        int                        `json:"risk_score"`
	TriggeredRules   []FinancialTriggeredRule   `json:"triggered_rules"`
	RequiredControls []FinancialRequiredControl `json:"required_controls"`
	IdentifiedGaps   []FinancialIdentifiedGap   `json:"identified_gaps"`
	StopLinesHit     []FinancialStopLineHit     `json:"stop_lines_hit"`
	EscalationLevel  string                     `json:"escalation_level,omitempty"`
	Summary          string                     `json:"summary"`
	PolicyVersion    string                     `json:"policy_version"`
}

// FinancialTriggeredRule represents a triggered financial regulation rule
type FinancialTriggeredRule struct {
	Code        string   `json:"code"`
	Category    string   `json:"category"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Severity    Severity `json:"severity"`
	ScoreDelta  int      `json:"score_delta"`
	DORARef     string   `json:"dora_ref,omitempty"`
	MaRiskRef   string   `json:"marisk_ref,omitempty"`
	BAITRef     string   `json:"bait_ref,omitempty"`
	MiFIDRef    string   `json:"mifid_ref,omitempty"`
	Rationale   string   `json:"rationale"`
}

// FinancialRequiredControl represents a required control
type FinancialRequiredControl struct {
	ID             string   `json:"id"`
	Title          string   `json:"title"`
	Category       string   `json:"category"`
	Description    string   `json:"description"`
	WhatToDo       string   `json:"what_to_do"`
	EvidenceNeeded []string `json:"evidence_needed,omitempty"`
	Effort         string   `json:"effort"`
	DORARef        string   `json:"dora_ref,omitempty"`
	MaRiskRef      string   `json:"marisk_ref,omitempty"`
	BAITRef        string   `json:"bait_ref,omitempty"`
}

// FinancialIdentifiedGap represents an identified compliance gap
type FinancialIdentifiedGap struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Severity    Severity `json:"severity"`
	Controls    []string `json:"controls,omitempty"`
	LegalRefs   []string `json:"legal_refs,omitempty"`
}

// FinancialStopLineHit represents a hit stop line
type FinancialStopLineHit struct {
	ID      string `json:"id"`
	Title   string `json:"title"`
	Message string `json:"message"`
	Outcome string `json:"outcome"`
}
