#!/usr/bin/env python
# encoding: utf-8
#
#  ------------------------------------------------------------------------------
#  Name: mapper.py
#  Version: 0.0.1
#  Summary: Bacen IF.data AutoScraper & Data Manager
#           Este sistema foi projetado para automatizar o download dos
#           relatórios da ferramenta IF.data do Banco Central do Brasil.
#           Criado para facilitar a integração com ferramentas automatizadas de
#           análise e visualização de dados, garantido acesso fácil e oportuno
#           aos dados.
#
#  Author: Alexsander Lopes Camargos
#  Author-email: alcamargos@vivaldi.net
#
#  License: MIT
#  ------------------------------------------------------------------------------

"""
Bacen IF.data AutoScraper & Data Manager

This script is designed to automate the download of reports from the Banco Central do Brasil's
IF.data tool. It facilitates the integration with automated data analysis and visualization tools,
ensuring easy and timely access to data.

Author: Alexsander Lopes Camargos
License: MIT
"""

from enum import StrEnum
from typing import Final

from bacen_ifdata.data_transformer.schemas import (
    FINANCIAL_CONGLOMERATE_ASSETS_SCHEMA,
    FINANCIAL_CONGLOMERATE_CAPITAL_INFORMATION_SCHEMA,
    FINANCIAL_CONGLOMERATE_INCOME_STATEMENT_SCHEMA,
    FINANCIAL_CONGLOMERATE_LIABILITIES_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_GEOGRAPHIC_REGION_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_INDEXER_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_INDIVIDUALS_TYPE_MATURITY_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_LEGAL_PERSON_BUSINESS_SIZE_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_LEGAL_PERSON_ECONOMIC_ACTIVITY_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_LEGAL_PERSON_TYPE_MATURITY_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_NUMBER_CLIENTS_OPERATIONS_SCHEMA,
    FINANCIAL_CONGLOMERATE_PORTFOLIO_RISK_LEVEL_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_GEOGRAPHIC_REGION_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_INDEXER_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_INDIVIDUALS_TYPE_MATURITY_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_LEGAL_PERSON_BUSINESS_SIZE_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_LEGAL_PERSON_ECONOMIC_ACTIVITY_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_LEGAL_PERSON_TYPE_MATURITY_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_NUMBER_CLIENTS_OPERATIONS_SCHEMA,
    FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_RISK_LEVEL_SCHEMA,
    FINANCIAL_CONGLOMERATE_SUMMARY_SCHEMA,
    FOREIGN_EXCHANGE_QUARTERLY_FOREIGN_CURRENCY_FLOW_SCHEMA,
    INDIVIDUAL_INSTITUTION_ASSETS_SCHEMA,
    INDIVIDUAL_INSTITUTION_INCOME_STATEMENT_SCHEMA,
    INDIVIDUAL_INSTITUTION_LIABILITIES_SCHEMA,
    INDIVIDUAL_INSTITUTION_SUMMARY_SCHEMA,
    PRUDENTIAL_CONGLOMERATE_ASSETS_SCHEMA,
    PRUDENTIAL_CONGLOMERATE_CAPITAL_INFORMATION_SCHEMA,
    PRUDENTIAL_CONGLOMERATE_INCOME_STATEMENT_SCHEMA,
    PRUDENTIAL_CONGLOMERATE_LIABILITIES_SCHEMA,
    PRUDENTIAL_CONGLOMERATE_SEGMENTATION_SCHEMA,
    PRUDENTIAL_CONGLOMERATE_SUMMARY_SCHEMA,
)
from bacen_ifdata.data_transformer.schemas.interfaces import SchemaProtocol
from bacen_ifdata.scraper.institutions import InstitutionType as Institutions
from bacen_ifdata.scraper.reports import (
    ReportsFinancialConglomerates,
    ReportsFinancialConglomeratesSCR,
    ReportsForeignExchange,
    ReportsIndividualInstitutions,
    ReportsPrudentialConglomerates,
)

# Schema mapping by institution and report type.
SCHEMA_BY_INSTITUTION_AND_REPORT: Final[dict[Institutions, dict[StrEnum, SchemaProtocol]]] = {
    # Prudential Conglomerates schemas.
    Institutions.PRUDENTIAL_CONGLOMERATES: {
        ReportsPrudentialConglomerates.SUMMARY: PRUDENTIAL_CONGLOMERATE_SUMMARY_SCHEMA,
        ReportsPrudentialConglomerates.ASSETS: PRUDENTIAL_CONGLOMERATE_ASSETS_SCHEMA,
        ReportsPrudentialConglomerates.LIABILITIES: PRUDENTIAL_CONGLOMERATE_LIABILITIES_SCHEMA,
        ReportsPrudentialConglomerates.INCOME_STATEMENT: PRUDENTIAL_CONGLOMERATE_INCOME_STATEMENT_SCHEMA,
        ReportsPrudentialConglomerates.CAPITAL_INFORMATION: PRUDENTIAL_CONGLOMERATE_CAPITAL_INFORMATION_SCHEMA,
        ReportsPrudentialConglomerates.SEGMENTATION: PRUDENTIAL_CONGLOMERATE_SEGMENTATION_SCHEMA,
    },
    # Financial Conglomerates schemas.
    Institutions.FINANCIAL_CONGLOMERATES: {
        ReportsFinancialConglomerates.SUMMARY: FINANCIAL_CONGLOMERATE_SUMMARY_SCHEMA,
        ReportsFinancialConglomerates.ASSETS: FINANCIAL_CONGLOMERATE_ASSETS_SCHEMA,
        ReportsFinancialConglomerates.CAPITAL_INFORMATION: FINANCIAL_CONGLOMERATE_CAPITAL_INFORMATION_SCHEMA,
        ReportsFinancialConglomerates.LIABILITIES: FINANCIAL_CONGLOMERATE_LIABILITIES_SCHEMA,
        ReportsFinancialConglomerates.INCOME_STATEMENT: FINANCIAL_CONGLOMERATE_INCOME_STATEMENT_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_INDIVIDUALS_TYPE_MATURITY: FINANCIAL_CONGLOMERATE_PORTFOLIO_INDIVIDUALS_TYPE_MATURITY_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_LEGAL_PERSON_TYPE_MATURITY: FINANCIAL_CONGLOMERATE_PORTFOLIO_LEGAL_PERSON_TYPE_MATURITY_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_LEGAL_PERSON_ECONOMIC_ACTIVITY: FINANCIAL_CONGLOMERATE_PORTFOLIO_LEGAL_PERSON_ECONOMIC_ACTIVITY_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_LEGAL_PERSON_BUSINESS_SIZE: FINANCIAL_CONGLOMERATE_PORTFOLIO_LEGAL_PERSON_BUSINESS_SIZE_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_NUMBER_CLIENTS_OPERATIONS: FINANCIAL_CONGLOMERATE_PORTFOLIO_NUMBER_CLIENTS_OPERATIONS_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_RISK_LEVEL: FINANCIAL_CONGLOMERATE_PORTFOLIO_RISK_LEVEL_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_INDEXER: FINANCIAL_CONGLOMERATE_PORTFOLIO_INDEXER_SCHEMA,
        ReportsFinancialConglomerates.PORTFOLIO_GEOGRAPHIC_REGION: FINANCIAL_CONGLOMERATE_PORTFOLIO_GEOGRAPHIC_REGION_SCHEMA,
    },
    # Financial Conglomerates SCR schemas.
    Institutions.FINANCIAL_CONGLOMERATES_SCR: {
        ReportsFinancialConglomeratesSCR.PORTFOLIO_INDIVIDUALS_TYPE_MATURITY: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_INDIVIDUALS_TYPE_MATURITY_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_LEGAL_PERSON_TYPE_MATURITY: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_LEGAL_PERSON_TYPE_MATURITY_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_LEGAL_PERSON_ECONOMIC_ACTIVITY: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_LEGAL_PERSON_ECONOMIC_ACTIVITY_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_LEGAL_PERSON_BUSINESS_SIZE: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_LEGAL_PERSON_BUSINESS_SIZE_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_NUMBER_CLIENTS_OPERATIONS: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_NUMBER_CLIENTS_OPERATIONS_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_RISK_LEVEL: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_RISK_LEVEL_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_INDEXER: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_INDEXER_SCHEMA,
        ReportsFinancialConglomeratesSCR.PORTFOLIO_GEOGRAPHIC_REGION: FINANCIAL_CONGLOMERATE_SCR_PORTFOLIO_GEOGRAPHIC_REGION_SCHEMA,
    },
    # Individual Institutions schemas.
    Institutions.INDIVIDUAL_INSTITUTIONS: {
        ReportsIndividualInstitutions.SUMMARY: INDIVIDUAL_INSTITUTION_SUMMARY_SCHEMA,
        ReportsIndividualInstitutions.ASSETS: INDIVIDUAL_INSTITUTION_ASSETS_SCHEMA,
        ReportsIndividualInstitutions.LIABILITIES: INDIVIDUAL_INSTITUTION_LIABILITIES_SCHEMA,
        ReportsIndividualInstitutions.INCOME_STATEMENT: INDIVIDUAL_INSTITUTION_INCOME_STATEMENT_SCHEMA,
    },
    # Foreign Exchange schemas.
    Institutions.FOREIGN_EXCHANGE: {
        ReportsForeignExchange.QUARTERLY_FOREIGN_CURRENCY_FLOW: FOREIGN_EXCHANGE_QUARTERLY_FOREIGN_CURRENCY_FLOW_SCHEMA,
    },
}

__all__ = [
    'SCHEMA_BY_INSTITUTION_AND_REPORT',
]
