from __future__ import annotations

from app.services.expense_claim_tenant_scope import ExpenseClaimTenantScopeMixin
from app.services.tenant_registry import DEFAULT_TENANT_ID

FINANCE_DASHBOARD_CLAIM_SCOPE = "expense_case_tenant"
FINANCE_DASHBOARD_DEFAULT_BUDGET_SCOPE = "legacy_default_budget"
FINANCE_DASHBOARD_NO_BUDGET_SCOPE = "budget_unavailable"
FINANCE_DASHBOARD_TASK_TYPE = "finance_dashboard_snapshot"


def normalize_finance_dashboard_tenant_id(value: str | None) -> str:
    return ExpenseClaimTenantScopeMixin.normalize_tenant_id(value)


def finance_dashboard_includes_legacy_budget(tenant_id: str | None) -> bool:
    """旧预算表没有 tenant_id，只允许 default 租户读取。"""

    return normalize_finance_dashboard_tenant_id(tenant_id) == DEFAULT_TENANT_ID


def resolve_finance_dashboard_data_scope(tenant_id: str | None) -> str:
    budget_scope = (
        FINANCE_DASHBOARD_DEFAULT_BUDGET_SCOPE
        if finance_dashboard_includes_legacy_budget(tenant_id)
        else FINANCE_DASHBOARD_NO_BUDGET_SCOPE
    )
    return f"claims:{FINANCE_DASHBOARD_CLAIM_SCOPE};budget:{budget_scope}"
