"""
财务指标映射配置
用于将中文指标名称映射为英文代码
"""

# 利润表指标映射
PROFIT_STATEMENT_MAPPING = {
    "报表核心指标": "core_indicators",
    "*净利润": "net_profit",
    "*营业总收入": "total_revenue",
    # "*营业总成本": "total_cost",
    "*归属于母公司所有者的净利润": "net_profit_to_parent",
    "*扣除非经常性损益后的净利润": "net_profit_excl_nonrecurring",
    "报表全部指标": "all_indicators",
    # TODO: 需要确认
    "营业总收入": "total_revenue_detail",
    "营业收入": "operating_revenue",
    "营业总成本": "total_cost_detail",
    "营业成本": "operating_cost",

    "税金及附加": "tax_and_surcharges",
    "销售费用": "selling_expenses",
    "管理费用": "management_expenses",
    "研发费用": "rd_expenses",
    "财务费用": "financial_expenses",
    "利息费用": "interest_expense",

    "利息收入": "interest_income",

    "资产减值损失": "asset_impairment_loss",
    "信用减值损失": "credit_impairment_loss",
    "加：公允价值变动收益": "fair_value_change_income",
    "投资收益": "investment_income",
    "其中：联营企业和合营企业的投资收益": "investment_income_from_associates",
    "资产处置收益": "asset_disposal_income",
    "其他收益": "other_income",
    "营业利润": "operating_profit",
    "营业外收入": "non_operating_income",
    "非流动资产处置利得": "non_current_asset_disposal_gain",
    "营业外支出": "non_operating_expenses",
    "非流动资产处置损失": "non_current_asset_disposal_loss",
    "利润总额": "total_profit",
    "净利润差额": "net_profit_balance",
    "所得税费用": "income_tax_expense",
    "净利润": "net_profit_final",
    "持续经营净利润": "net_profit_from_continuing_operations",
    "归属于母公司所有者的净利润": "net_profit_to_parent_final",
    "少数股东损益": "minority_interest_income",
    "扣除非经常性损益后的净利润": "net_profit_excl_nonrecurring_final",
    "每股收益": "eps",
    "基本每股收益": "basic_eps",
    "稀释每股收益": "diluted_eps",
    "其他综合收益": "other_comprehensive_income",
    "归属母公司所有者的其他综合收益": "other_comprehensive_income_to_parent",
    "综合收益总额": "total_comprehensive_income",
    "归属于母公司股东的综合收益总额": "total_comprehensive_income_to_parent",
    "归属于少数股东的综合收益总额": "total_comprehensive_income_to_minority",

    '营业收入': 'operating_revenue',  
    '营业成本': 'operating_cost',      
    '税金及附加': 'tax_and_surcharges', 
    '公允价值变动收益': 'fair_value_change_income', 
    '所得税费用': 'income_tax_expense', 
    '净利润': 'net_profit_final',      
    '少数股东损益': 'minority_interest_income', 
    '基本每股收益': 'basic_eps',      
    '稀释每股收益': 'diluted_eps',
    '营业利润': 'operating_profit',
    '利润总额': 'total_profit',
    '投资收益': 'investment_income',
    '信用减值损失': 'credit_impairment_loss',
    '资产减值损失': 'asset_impairment_loss',
    '资产处置收益': 'asset_disposal_income',
}

# 资产负债表指标映射
BALANCE_SHEET_MAPPING = {
    # 流动资产
    "流动资产合计": "total_current_assets",
    "货币资金": "monetary_funds",
    "交易性金融资产": "trading_financial_assets",
    "衍生金融资产": "derivative_financial_assets",
    "应收票据": "notes_receivable",
    "应收账款": "accounts_receivable",
    "应收款项融资": "receivables_financing",
    "预付款项": "prepayments",
    "其他应收款": "other_receivables",
    "存货": "inventory",
    "合同资产": "contract_assets",
    "持有待售资产": "assets_held_for_sale",
    "一年内到期的非流动资产": "non_current_assets_due_within_one_year",
    "其他流动资产": "other_current_assets",
    
    # 非流动资产
    "非流动资产合计": "total_non_current_assets",
    "发放贷款和垫款": "loans_and_advances",
    "债权投资": "debt_investments",
    "其他债权投资": "other_debt_investments",
    "长期股权投资": "long_term_equity_investments",
    "其他权益工具投资": "other_equity_investments",
    "其他非流动金融资产": "other_non_current_financial_assets",
    "投资性房地产": "investment_properties",
    "固定资产": "fixed_assets",
    "在建工程": "construction_in_progress",
    "生产性生物资产": "productive_biological_assets",
    "油气资产": "oil_and_gas_assets",
    "使用权资产": "right_of_use_assets",
    "无形资产": "intangible_assets",
    "开发支出": "development_expenses",
    "商誉": "goodwill",
    "长期待摊费用": "long_term_prepaid_expenses",
    "递延所得税资产": "deferred_tax_assets",
    "其他非流动资产": "other_non_current_assets",
    
    # 资产总计
    "资产合计": "total_assets",
    "*资产合计": "total_assets",  # 保留，因为可能有不同的表头格式
    
    # 流动负债
    "流动负债合计": "total_current_liabilities",
    "短期借款": "short_term_borrowings",
    "交易性金融负债": "trading_financial_liabilities",
    "衍生金融负债": "derivative_financial_liabilities",
    "应付票据": "notes_payable",
    "应付账款": "accounts_payable",
    "合同负债": "contract_liabilities",
    "预收款项": "advances_from_customers",
    "应付职工薪酬": "employee_benefits_payable",
    "应交税费": "taxes_payable",
    "其他应付款": "other_payables",
    "持有待售负债": "liabilities_held_for_sale",
    "一年内到期的非流动负债": "non_current_liabilities_due_within_one_year",
    "其他流动负债": "other_current_liabilities",
    
    # 非流动负债
    "非流动负债合计": "total_non_current_liabilities",
    "长期借款": "long_term_borrowings",
    "应付债券": "bonds_payable",
    "租赁负债": "lease_liabilities",
    "长期应付款": "long_term_payables",
    "长期应付职工薪酬": "long_term_employee_benefits_payable",
    "预计负债": "estimated_liabilities",
    "递延收益": "deferred_income",
    "递延所得税负债": "deferred_tax_liabilities",
    "其他非流动负债": "other_non_current_liabilities",
    
    # 负债总计
    "负债合计": "total_liabilities",
    "*负债合计": "total_liabilities",  # 保留，因为可能有不同的表头格式
    
    # 所有者权益
    "所有者权益合计": "total_equity",
    "股本": "paid_in_capital",
    "资本公积": "capital_reserve",
    "其他综合收益": "other_comprehensive_income_equity",
    "专项储备": "special_reserve",
    "盈余公积": "surplus_reserve",
    "未分配利润": "undistributed_profits",
    "归属于母公司所有者权益合计": "total_equity_attributable_to_parent",
    "少数股东权益": "minority_interests",
    
    # 负债和所有者权益总计
    "负债和所有者权益合计": "total_liabilities_and_equity",
    "*所有者权益（或股东权益）合计": "total_equity",  # 保留，因为可能有不同的表头格式
    "所有者权益（或股东权益）合计": "total_equity",  # 保留，因为可能有不同的表头格式
    "负债和所有者权益（或股东权益）合计": "total_liabilities_and_equity"  # 保留，因为可能有不同的表头格式
}

# 现金流量表指标映射
CASH_FLOW_STATEMENT_MAPPING = {
    # 经营活动现金流量
    "经营活动产生的现金流量净额": "net_cash_flows_from_operating_activities",
    "*经营活动产生的现金流量净额": "net_cash_flows_from_operating_activities",  # 保留，因为可能有不同的表头格式
    
    # 经营活动现金流入
    "销售商品、提供劳务收到的现金": "cash_received_from_sales_of_goods",
    "收到的税费返还": "tax_refunds_received",
    "收到其他与经营活动有关的现金": "other_cash_received_related_to_operating_activities",
    "经营活动现金流入小计": "total_cash_inflows_from_operating_activities",
    
    # 经营活动现金流出
    "购买商品、接受劳务支付的现金": "cash_paid_for_goods_and_services",
    "支付给职工以及为职工支付的现金": "cash_paid_to_and_for_employees",
    "支付的各项税费": "taxes_paid",
    "支付其他与经营活动有关的现金": "other_cash_paid_related_to_operating_activities",
    "经营活动现金流出小计": "total_cash_outflows_from_operating_activities",
    
    # 投资活动现金流量
    "投资活动产生的现金流量净额": "net_cash_flows_from_investing_activities",
    "*投资活动产生的现金流量净额": "net_cash_flows_from_investing_activities",  # 保留，因为可能有不同的表头格式
    
    # 投资活动现金流入
    "取得投资收益收到的现金": "cash_received_from_investment_returns",
    "处置固定资产、无形资产和其他长期资产收回的现金净额": "net_cash_received_from_disposal_of_fixed_assets",
    "处置子公司及其他营业单位收到的现金净额": "net_cash_received_from_disposal_of_subsidiaries",
    "收到其他与投资活动有关的现金": "other_cash_received_related_to_investing_activities",
    "投资活动现金流入小计": "total_cash_inflows_from_investing_activities",
    
    # 投资活动现金流出
    "购建固定资产、无形资产和其他长期资产支付的现金": "cash_paid_for_construction_of_fixed_assets",
    "投资支付的现金": "cash_paid_for_investments",
    "取得子公司及其他营业单位支付的现金净额": "net_cash_paid_for_acquisition_of_subsidiaries",
    "支付其他与投资活动有关的现金": "other_cash_paid_related_to_investing_activities",
    "投资活动现金流出小计": "total_cash_outflows_from_investing_activities",
    
    # 筹资活动现金流量
    "筹资活动产生的现金流量净额": "net_cash_flows_from_financing_activities",
    "*筹资活动产生的现金流量净额": "net_cash_flows_from_financing_activities",  # 保留，因为可能有不同的表头格式
    
    # 筹资活动现金流入
    "吸收投资收到的现金": "cash_received_from_investments_by_owners",
    "取得借款收到的现金": "cash_received_from_borrowings",
    "收到其他与筹资活动有关的现金": "other_cash_received_related_to_financing_activities",
    "筹资活动现金流入小计": "total_cash_inflows_from_financing_activities",
    
    # 筹资活动现金流出
    "偿还债务支付的现金": "cash_repayments_of_borrowings",
    "分配股利、利润或偿付利息支付的现金": "cash_payments_for_distribution_of_dividends",
    "支付其他与筹资活动有关的现金": "other_cash_paid_related_to_financing_activities",
    "筹资活动现金流出小计": "total_cash_outflows_from_financing_activities",
    
    # 汇率变动对现金及现金等价物的影响
    "汇率变动对现金及现金等价物的影响": "effect_of_exchange_rate_changes_on_cash",
    
    # 现金及现金等价物净增加额
    "现金及现金等价物净增加额": "net_increase_in_cash_and_cash_equivalents",
    "*现金及现金等价物净增加额": "net_increase_in_cash_and_cash_equivalents",  # 保留，因为可能有不同的表头格式
    
    # 期初现金及现金等价物余额
    "期初现金及现金等价物余额": "cash_and_cash_equivalents_at_beginning_of_period",
    
    # 期末现金及现金等价物余额
    "期末现金及现金等价物余额": "cash_and_cash_equivalents_at_end_of_period",
    
    # 补充资料 - 净利润调节为经营活动现金流量
    "净利润": "net_profit",
    "资产减值准备": "asset_impairment_provisions",
    "固定资产折旧": "depreciation_of_fixed_assets",
    "无形资产摊销": "amortization_of_intangible_assets",
    "长期待摊费用摊销": "amortization_of_long_term_prepaid_expenses",
    "处置固定资产、无形资产和其他长期资产的损失": "disposal_loss_on_fixed_assets",
    "固定资产报废损失": "loss_on_retirement_of_fixed_assets",
    "公允价值变动损失": "fair_value_change_loss",
    "财务费用": "financial_expenses",
    "投资损失": "investment_loss",
    "递延所得税资产减少": "deferred_tax_assets_decrease",
    "递延所得税负债增加": "deferred_tax_liabilities_increase",
    "存货的减少": "decrease_in_inventory",
    "经营性应收项目的减少": "decrease_in_operating_receivables",
    "经营性应付项目的增加": "increase_in_operating_payables",
    "其他": "other_items",
    "经营活动产生的现金流量净额(调整后)": "net_cash_flows_from_operating_activities_adjusted",
    
    # 现金及现金等价物变动情况
    "现金的期末余额": "cash_at_end_of_period",
    "现金等价物的期末余额": "cash_equivalents_at_end_of_period",
    "减：现金等价物的期初余额": "cash_equivalents_at_beginning_of_period",
    "现金及现金等价物净增加额(调整后)": "cash_and_cash_equivalents_at_end_of_period_adjusted",
    "间接法-现金及现金等价物净增加额": "net_increase_in_cash_and_cash_equivalents_adjusted",
    
    # 银行类金融机构特有字段
    "客户存款和同业存放款项净增加额": "net_increase_in_customer_deposits_and_interbank_deposits",
    "向中央银行借款净增加额": "net_increase_in_borrowings_from_central_bank",
    "拆入资金净增加额": "net_increase_in_borrowed_funds",
    "拆出资金净减少额": "net_decrease_in_lent_funds",
    "存放中央银行和同业款项净减少额": "net_decrease_in_deposits_with_central_bank_and_interbank",
    "发放贷款和垫款净增加额": "net_increase_in_loans_and_advances",
    "收回投资收到的现金": "cash_received_from_investment_repayments",
    "投资支付的现金": "cash_paid_for_investments",
    "吸收投资收到的现金": "cash_received_from_investments_by_owners",
    "发行债券收到的现金": "cash_received_from_bond_issuance",
    "偿还债务支付的现金": "cash_repayments_of_borrowings",
    "分配股利、利润或偿付利息支付的现金": "cash_payments_for_distribution_of_dividends"
}

# 合并所有映射
INDICATOR_MAPPING = {
    **PROFIT_STATEMENT_MAPPING,
    **BALANCE_SHEET_MAPPING,
    **CASH_FLOW_STATEMENT_MAPPING
}