export type YearlyFinancials = {
    year: number;
    revenue: number;
    net_income: number;
};

export type GrowthTransition = {
    from_year: number;
    to_year: number;
    previous_revenue: number;
    current_revenue: number;
    previous_net_income: number;
    current_net_income: number;
    revenue_growth_pct: number | null;
    net_income_growth_pct: number | null;
    growth_score: number | null;
    status: string;
    revenue_status: string;
    net_income_status: string;
    missing_years: number[];
    net_income_delta: number | null;
    flags: string[];
};

export type RatioScore = {
    score: number | null;
    label: string;
    inputs: Record<string, number | null>;
};

export type GrowthRatios = {
    profitability?: RatioScore;
    liquidity?: RatioScore;
    solvency?: RatioScore;
    efficiency?: RatioScore;
};

export type GrowthAnalysis = {
    company_name: string | null;
    account_type: string | null;
    years: YearlyFinancials[];
    transitions: GrowthTransition[];
    growth_score: number | null;
    trend: 'improving' | 'declining' | 'stable' | 'insufficient_data' | string;
    grade: string | null;
    sync: {
        synced_at: string | null;
        refreshing: boolean;
        last_error: string | null;
    };
    data_quality: {
        missing_years: number[];
        has_sign_flips: boolean;
        status: string | null;
    };
    metrics: {
        latest_revenue: number | null;
        latest_net_income: number | null;
        latest_net_margin: number | null;
        revenue_growth_pct: number | null;
        net_income_growth_pct: number | null;
        net_income_delta: number | null;
        best_transition_score: number | null;
        weakest_transition_score: number | null;
        score_range: number | null;
        score_volatility: number | null;
        scored_transition_count: number;
        coverage_years: number;
    };
    ratios?: GrowthRatios;
};

export type AdvisorImpact = 'high' | 'medium' | 'low';

export type AdvisorActionItem = {
    title: string;
    description: string;
    impact: AdvisorImpact | string;
};

export type GradeProjection = {
    grade: string;
    score: number;
};

export type AdvisorAdvice = {
    critical_must_do: AdvisorActionItem[];
    areas_needing_focus: AdvisorActionItem[];
    good_to_have: AdvisorActionItem[];
    three_month_plan: {
        month_1: string[];
        month_2: string[];
        month_3: string[];
    };
    next_grade_projection: {
        months_3: GradeProjection;
        months_6: GradeProjection;
    };
    upskill_recommendation: {
        title: string;
        description: string;
    };
};

export type SavedAdvisorAdvice = AdvisorAdvice & {
    generated_at: string;
    is_stale: boolean;
};

export type ExternalCompany = {
    id: string;
    name: string;
    account_type: string;
};
