package domain import ( "context" "time" "gorm.io/datatypes" ) // TrustMetrics represents trust and quality metrics for organizations and data type TrustMetrics struct { ID string `gorm:"primaryKey;type:text"` OrganizationID string `gorm:"type:text;not null;index"` MetricType string `gorm:"type:varchar(50);not null"` // organization, resource_flow, site MetricName string `gorm:"type:varchar(100);not null"` Value float64 `gorm:"type:decimal(5,4)"` // 0.0 to 1.0 Score string `gorm:"type:varchar(20)"` // excellent, good, fair, poor Evidence datatypes.JSON `gorm:"type:jsonb"` // Supporting data LastUpdated time.Time `gorm:"autoUpdateTime"` ValidUntil time.Time `gorm:"index"` // Associations Organization *Organization `gorm:"foreignKey:OrganizationID"` } // TableName specifies the table name for GORM func (TrustMetrics) TableName() string { return "trust_metrics" } // DataQualityProfile represents a comprehensive quality profile for an organization type DataQualityProfile struct { OrganizationID string `json:"organization_id"` OverallScore float64 `json:"overall_score"` // 0-1 Completeness float64 `json:"completeness"` // 0-1 Accuracy float64 `json:"accuracy"` // 0-1 Timeliness float64 `json:"timeliness"` // 0-1 Consistency float64 `json:"consistency"` // 0-1 LastAssessed time.Time `json:"last_assessed"` AssessmentPeriod time.Duration `json:"assessment_period"` Metrics []TrustMetrics `json:"metrics"` Recommendations []string `json:"recommendations"` RiskFactors []RiskFactor `json:"risk_factors"` } // RiskFactor represents a risk factor affecting trust type RiskFactor struct { Type string `json:"type"` // data_quality, verification, historical Description string `json:"description"` Severity float64 `json:"severity"` // 0-1 Impact string `json:"impact"` // low, medium, high Mitigation string `json:"mitigation"` } // TrustMetricsRepository defines the interface for trust metrics operations type TrustMetricsRepository interface { Create(ctx context.Context, metric *TrustMetrics) error GetByOrganization(ctx context.Context, orgID string) ([]*TrustMetrics, error) GetByType(ctx context.Context, orgID, metricType string) ([]*TrustMetrics, error) Update(ctx context.Context, metric *TrustMetrics) error Delete(ctx context.Context, id string) error GetLatestProfile(ctx context.Context, orgID string) (*DataQualityProfile, error) } // VerificationStatus represents verification status for data elements type VerificationStatus string const ( VerificationUnverified VerificationStatus = "unverified" VerificationPending VerificationStatus = "pending" VerificationVerified VerificationStatus = "verified" VerificationRejected VerificationStatus = "rejected" ) // VerifiedData represents verified data elements type VerifiedData struct { ID string `gorm:"primaryKey;type:text"` OrganizationID string `gorm:"type:text;not null;index"` DataType string `gorm:"type:varchar(50);not null"` // organization, resource_flow, site DataID string `gorm:"type:text;not null"` Status VerificationStatus `gorm:"type:varchar(20);default:'unverified'"` VerifiedBy string `gorm:"type:text"` VerifiedAt *time.Time `gorm:"index"` Evidence datatypes.JSON `gorm:"type:jsonb"` ExpiresAt *time.Time `gorm:"index"` Notes string `gorm:"type:text"` // Associations Organization *Organization `gorm:"foreignKey:OrganizationID"` } // TableName specifies the table name for GORM func (VerifiedData) TableName() string { return "verified_data" } // HistoricalSuccess represents historical success metrics type HistoricalSuccess struct { ID string `gorm:"primaryKey;type:text"` OrganizationID string `gorm:"type:text;not null;index"` MatchID string `gorm:"type:text;index"` MetricType string `gorm:"type:varchar(50);not null"` // completion_rate, satisfaction, volume Value float64 `gorm:"type:decimal(5,4)"` Period string `gorm:"type:varchar(20)"` // monthly, quarterly, yearly RecordedAt time.Time `gorm:"not null;index"` Data datatypes.JSON `gorm:"type:jsonb"` // Additional context // Associations Organization *Organization `gorm:"foreignKey:OrganizationID"` } // TableName specifies the table name for GORM func (HistoricalSuccess) TableName() string { return "historical_success" } // TrustScore represents an overall trust score for an organization type TrustScore struct { OrganizationID string `json:"organization_id"` OverallScore float64 `json:"overall_score"` // 0-1 DataQualityScore float64 `json:"data_quality_score"` // 0-1 VerificationScore float64 `json:"verification_score"` // 0-1 HistoricalScore float64 `json:"historical_score"` // 0-1 PeerReviewScore float64 `json:"peer_review_score"` // 0-1 LastCalculated time.Time `json:"last_calculated"` ConfidenceLevel float64 `json:"confidence_level"` // 0-1 ScoreBreakdown map[string]float64 `json:"score_breakdown"` RiskFactors []RiskFactor `json:"risk_factors"` Recommendations []string `json:"recommendations"` }