package quality

import (
	"time"
)

// Severity represents the severity level of a finding
type Severity int

const (
	SeverityT1 Severity = iota + 1 // Auto-fixable (unused imports, debug logs)
	SeverityT2                       // Quick manual (unused vars, dead exports)
	SeverityT3                       // Needs judgment (near-dupes, single_use abstractions)
	SeverityT4                       // Major refactor (god components, mixed concerns)
)

// Status represents the status of a finding
type Status string

const (
	StatusOpen        Status = "open"
	StatusFixed       Status = "fixed"
	StatusWontfix     Status = "wontfix"
	StatusFalsePositive Status = "false_positive"
	StatusIgnored     Status = "ignored"
)

// Finding represents a code quality issue
type Finding struct {
	ID          string            `json:"id"`
	Type        string            `json:"type"`
	Title       string            `json:"title"`
	Description string            `json:"description"`
	File        string            `json:"file"`
	Line        int               `json:"line"`
	EndLine     int               `json:"end_line,omitempty"`
	Severity    Severity          `json:"severity"`
	Score       int               `json:"score"`
	Status      Status            `json:"status"`
	Metadata    map[string]string `json:"metadata,omitempty"`
	CreatedAt   time.Time         `json:"created_at"`
	UpdatedAt   time.Time         `json:"updated_at"`
}

// FunctionInfo represents extracted function/method information
type FunctionInfo struct {
	Name             string   `json:"name"`
	File             string   `json:"file"`
	Line             int      `json:"line"`
	EndLine          int      `json:"end_line"`
	LOC              int      `json:"loc"`
	Body             string   `json:"body"`
	Normalized       string   `json:"normalized"`
	BodyHash         string   `json:"body_hash"`
	Params           []string `json:"params"`
	ReturnAnnotation string   `json:"return_annotation,omitempty"`
}

// ClassInfo represents extracted class/component information
type ClassInfo struct {
	Name         string                   `json:"name"`
	File         string                   `json:"file"`
	Line         int                      `json:"line"`
	LOC          int                      `json:"loc"`
	Methods      []FunctionInfo           `json:"methods"`
	Attributes   []string                 `json:"attributes"`
	BaseClasses  []string                 `json:"base_classes"`
	Metrics      map[string]int           `json:"metrics"`
}

// ScanResult represents the result of a quality scan
type ScanResult struct {
	Findings     []Finding `json:"findings"`
	Score        int       `json:"score"`
	StrictScore  int       `json:"strict_score"`
	FilesChecked int       `json:"files_checked"`
	Duration     string    `json:"duration"`
	Timestamp    time.Time `json:"timestamp"`
}

// Scorecard represents the health scorecard
type Scorecard struct {
	TotalScore      int              `json:"total_score"`
	StrictScore     int              `json:"strict_score"`
	TargetScore     int              `json:"target_score"`
	FindingsByType  map[string]int   `json:"findings_by_type"`
	FindingsByTier map[Severity]int  `json:"findings_by_tier"`
	StatusByType    map[string]int   `json:"status_by_type"`
	LastScan        time.Time        `json:"last_scan"`
}

// Language represents a programming language configuration
type Language struct {
	Name         string   `json:"name"`
	Extensions   []string `json:"extensions"`
	MarkerFiles  []string `json:"marker_files"`
	DefaultSrc   string   `json:"default_src"`
}

// Config represents the quality analysis configuration
type Config struct {
	Path           string      `json:"path"`
	Language       string      `json:"language,omitempty"`
	Exclude        []string    `json:"exclude,omitempty"`
	Threshold      int         `json:"threshold,omitempty"`
	MinLOC         int         `json:"min_loc,omitempty"`
	TargetScore    int         `json:"target_score,omitempty"`
	ResetSubjective bool       `json:"reset_subjective,omitempty"`
	NoBadge        bool        `json:"no_badge,omitempty"`
	BadgePath      string      `json:"badge_path,omitempty"`
}
