INTERVALS = {
    '1m',
    '2m',
    '5m',
    '15m',
    '30m',
    '60m',
    '90m',
    '1h',
    '4h',
    '1d',
    '5d',
    '1wk',
    '1mo',
    '3mo',
}

PERIOD_RANGES = {'1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max'}

EVENTS_SET = {'div', 'split', 'earn', 'capitalGain'}

EVENTS = ','.join(EVENTS_SET)

QUOTE_SUMMARY_MODULES_SET = {
    'quoteType',
    'assetProfile',
    'summaryProfile',
    'summaryDetail',
    'incomeStatementHistory',
    'incomeStatementHistoryQuarterly',
    'balanceSheetHistory',
    'balanceSheetHistoryQuarterly',
    'cashflowStatementHistory',
    'cashflowStatementHistoryQuarterly',
    # 'esgScores',
    'price',
    'defaultKeyStatistics',
    'financialData',
    'calendarEvents',
    'secFilings',
    'upgradeDowngradeHistory',
    'institutionOwnership',
    'fundOwnership',
    'majorDirectHolders',
    'majorHoldersBreakdown',
    'insiderTransactions',
    'insiderHolders',
    'netSharePurchaseActivity',
    'earnings',
    'earningsHistory',
    'earningsTrend',
    'industryTrend',
    'indexTrend',
    'sectorTrend',
    'recommendationTrend',
    'pageViews',
    # 'details',
    # 'fundProfile',
    # 'futuresChain',
    # 'topHoldings',
    # 'fundPerformance'
}

QUOTE_SUMMARY_MODULES = ','.join(QUOTE_SUMMARY_MODULES_SET)

CALENDAR_EVENT_MODULES_SET = {'ipoEvents', 'secReports', 'earnings', 'economicEvents'}

CALENDAR_EVENT_MODULES = ','.join(CALENDAR_EVENT_MODULES_SET)

FREQUENCIES = {'annual', 'quarterly', 'trailing'}

INCOME_STATEMENT_TYPES_SET = {
    'TaxEffectOfUnusualItems',
    'TaxRateForCalcs',
    'NormalizedEBITDA',
    'NormalizedDilutedEPS',
    'NormalizedBasicEPS',
    'TotalUnusualItems',
    'TotalUnusualItemsExcludingGoodwill',
    'NetIncomeFromContinuingOperationNetMinorityInterest',
    'ReconciledDepreciation',
    'ReconciledCostOfRevenue',
    'EBITDA',
    'EBIT',
    'NetInterestIncome',
    'InterestExpense',
    'InterestIncome',
    'ContinuingAndDiscontinuedDilutedEPS',
    'ContinuingAndDiscontinuedBasicEPS',
    'NormalizedIncome',
    'NetIncomeFromContinuingAndDiscontinuedOperation',
    'TotalExpenses',
    'RentExpenseSupplemental',
    'ReportedNormalizedDilutedEPS',
    'ReportedNormalizedBasicEPS',
    'TotalOperatingIncomeAsReported',
    'DividendPerShare',
    'DilutedAverageShares',
    'BasicAverageShares',
    'DilutedEPS',
    'DilutedEPSOtherGainsLosses',
    'TaxLossCarryforwardDilutedEPS',
    'DilutedAccountingChange',
    'DilutedExtraordinary',
    'DilutedDiscontinuousOperations',
    'DilutedContinuousOperations',
    'BasicEPS',
    'BasicEPSOtherGainsLosses',
    'TaxLossCarryforwardBasicEPS',
    'BasicAccountingChange',
    'BasicExtraordinary',
    'BasicDiscontinuousOperations',
    'BasicContinuousOperations',
    'DilutedNIAvailtoComStockholders',
    'AverageDilutionEarnings',
    'NetIncomeCommonStockholders',
    'OtherunderPreferredStockDividend',
    'PreferredStockDividends',
    'NetIncome',
    'MinorityInterests',
    'NetIncomeIncludingNoncontrollingInterests',
    'NetIncomeFromTaxLossCarryforward',
    'NetIncomeExtraordinary',
    'NetIncomeDiscontinuousOperations',
    'NetIncomeContinuousOperations',
    'EarningsFromEquityInterestNetOfTax',
    'TaxProvision',
    'PretaxIncome',
    'OtherIncomeExpense',
    'OtherNonOperatingIncomeExpenses',
    'SpecialIncomeCharges',
    'GainOnSaleOfPPE',
    'GainOnSaleOfBusiness',
    'OtherSpecialCharges',
    'WriteOff',
    'ImpairmentOfCapitalAssets',
    'RestructuringAndMergernAcquisition',
    'SecuritiesAmortization',
    'EarningsFromEquityInterest',
    'GainOnSaleOfSecurity',
    'NetNonOperatingInterestIncomeExpense',
    'TotalOtherFinanceCost',
    'InterestExpenseNonOperating',
    'InterestIncomeNonOperating',
    'OperatingIncome',
    'OperatingExpense',
    'OtherOperatingExpenses',
    'OtherTaxes',
    'ProvisionForDoubtfulAccounts',
    'DepreciationAmortizationDepletionIncomeStatement',
    'DepletionIncomeStatement',
    'DepreciationAndAmortizationInIncomeStatement',
    'Amortization',
    'AmortizationOfIntangiblesIncomeStatement',
    'DepreciationIncomeStatement',
    'ResearchAndDevelopment',
    'SellingGeneralAndAdministration',
    'SellingAndMarketingExpense',
    'GeneralAndAdministrativeExpense',
    'OtherGandA',
    'InsuranceAndClaims',
    'RentAndLandingFees',
    'SalariesAndWages',
    'GrossProfit',
    'CostOfRevenue',
    'TotalRevenue',
    'ExciseTaxes',
    'OperatingRevenue',
    'LossAdjustmentExpense',
    'NetPolicyholderBenefitsAndClaims',
    'PolicyholderBenefitsGross',
    'PolicyholderBenefitsCeded',
    'OccupancyAndEquipment',
    'ProfessionalExpenseAndContractServicesExpense',
    'OtherNonInterestExpense',
}

BALANCE_SHEET_TYPES_SET = {
    'TreasurySharesNumber',
    'PreferredSharesNumber',
    'OrdinarySharesNumber',
    'ShareIssued',
    'NetDebt',
    'TotalDebt',
    'TangibleBookValue',
    'InvestedCapital',
    'WorkingCapital',
    'NetTangibleAssets',
    'CapitalLeaseObligations',
    'CommonStockEquity',
    'PreferredStockEquity',
    'TotalCapitalization',
    'TotalEquityGrossMinorityInterest',
    'MinorityInterest',
    'StockholdersEquity',
    'OtherEquityInterest',
    'GainsLossesNotAffectingRetainedEarnings',
    'OtherEquityAdjustments',
    'FixedAssetsRevaluationReserve',
    'ForeignCurrencyTranslationAdjustments',
    'MinimumPensionLiabilities',
    'UnrealizedGainLoss',
    'TreasuryStock',
    'RetainedEarnings',
    'AdditionalPaidInCapital',
    'CapitalStock',
    'OtherCapitalStock',
    'CommonStock',
    'PreferredStock',
    'TotalPartnershipCapital',
    'GeneralPartnershipCapital',
    'LimitedPartnershipCapital',
    'TotalLiabilitiesNetMinorityInterest',
    'TotalNonCurrentLiabilitiesNetMinorityInterest',
    'OtherNonCurrentLiabilities',
    'LiabilitiesHeldforSaleNonCurrent',
    'RestrictedCommonStock',
    'PreferredSecuritiesOutsideStockEquity',
    'DerivativeProductLiabilities',
    'EmployeeBenefits',
    'NonCurrentPensionAndOtherPostretirementBenefitPlans',
    'NonCurrentAccruedExpenses',
    'DuetoRelatedPartiesNonCurrent',
    'TradeandOtherPayablesNonCurrent',
    'NonCurrentDeferredLiabilities',
    'NonCurrentDeferredRevenue',
    'NonCurrentDeferredTaxesLiabilities',
    'LongTermDebtAndCapitalLeaseObligation',
    'LongTermCapitalLeaseObligation',
    'LongTermDebt',
    'LongTermProvisions',
    'CurrentLiabilities',
    'OtherCurrentLiabilities',
    'CurrentDeferredLiabilities',
    'CurrentDeferredRevenue',
    'CurrentDeferredTaxesLiabilities',
    'CurrentDebtAndCapitalLeaseObligation',
    'CurrentCapitalLeaseObligation',
    'CurrentDebt',
    'OtherCurrentBorrowings',
    'LineOfCredit',
    'CommercialPaper',
    'CurrentNotesPayable',
    'PensionandOtherPostRetirementBenefitPlansCurrent',
    'CurrentProvisions',
    'PayablesAndAccruedExpenses',
    'CurrentAccruedExpenses',
    'InterestPayable',
    'Payables',
    'OtherPayable',
    'DuetoRelatedPartiesCurrent',
    'DividendsPayable',
    'TotalTaxPayable',
    'IncomeTaxPayable',
    'AccountsPayable',
    'TotalAssets',
    'TotalNonCurrentAssets',
    'OtherNonCurrentAssets',
    'DefinedPensionBenefit',
    'NonCurrentPrepaidAssets',
    'NonCurrentDeferredAssets',
    'NonCurrentDeferredTaxesAssets',
    'DuefromRelatedPartiesNonCurrent',
    'NonCurrentNoteReceivables',
    'NonCurrentAccountsReceivable',
    'FinancialAssets',
    'InvestmentsAndAdvances',
    'OtherInvestments',
    'InvestmentinFinancialAssets',
    'HeldToMaturitySecurities',
    'AvailableForSaleSecurities',
    'FinancialAssetsDesignatedasFairValueThroughProfitorLossTotal',
    'TradingSecurities',
    'LongTermEquityInvestment',
    'InvestmentsinJointVenturesatCost',
    'InvestmentsInOtherVenturesUnderEquityMethod',
    'InvestmentsinAssociatesatCost',
    'InvestmentsinSubsidiariesatCost',
    'InvestmentProperties',
    'GoodwillAndOtherIntangibleAssets',
    'OtherIntangibleAssets',
    'Goodwill',
    'NetPPE',
    'AccumulatedDepreciation',
    'GrossPPE',
    'Leases',
    'ConstructionInProgress',
    'OtherProperties',
    'MachineryFurnitureEquipment',
    'BuildingsAndImprovements',
    'LandAndImprovements',
    'Properties',
    'CurrentAssets',
    'OtherCurrentAssets',
    'HedgingAssetsCurrent',
    'AssetsHeldForSaleCurrent',
    'CurrentDeferredAssets',
    'CurrentDeferredTaxesAssets',
    'RestrictedCash',
    'PrepaidAssets',
    'Inventory',
    'InventoriesAdjustmentsAllowances',
    'OtherInventories',
    'FinishedGoods',
    'WorkInProcess',
    'RawMaterials',
    'Receivables',
    'ReceivablesAdjustmentsAllowances',
    'OtherReceivables',
    'DuefromRelatedPartiesCurrent',
    'TaxesReceivable',
    'AccruedInterestReceivable',
    'NotesReceivable',
    'LoansReceivable',
    'AccountsReceivable',
    'AllowanceForDoubtfulAccountsReceivable',
    'GrossAccountsReceivable',
    'CashCashEquivalentsAndShortTermInvestments',
    'OtherShortTermInvestments',
    'CashAndCashEquivalents',
    'CashEquivalents',
    'CashFinancial',
    'CashCashEquivalentsAndFederalFundsSold',
}

CASH_FLOW_TYPES_SET = {
    'ForeignSales',
    'DomesticSales',
    'AdjustedGeographySegmentData',
    'FreeCashFlow',
    'RepurchaseOfCapitalStock',
    'RepaymentOfDebt',
    'IssuanceOfDebt',
    'IssuanceOfCapitalStock',
    'CapitalExpenditure',
    'InterestPaidSupplementalData',
    'IncomeTaxPaidSupplementalData',
    'EndCashPosition',
    'OtherCashAdjustmentOutsideChangeinCash',
    'BeginningCashPosition',
    'EffectOfExchangeRateChanges',
    'ChangesInCash',
    'OtherCashAdjustmentInsideChangeinCash',
    'CashFlowFromDiscontinuedOperation',
    'FinancingCashFlow',
    'CashFromDiscontinuedFinancingActivities',
    'CashFlowFromContinuingFinancingActivities',
    'NetOtherFinancingCharges',
    'InterestPaidCFF',
    'ProceedsFromStockOptionExercised',
    'CashDividendsPaid',
    'PreferredStockDividendPaid',
    'CommonStockDividendPaid',
    'NetPreferredStockIssuance',
    'PreferredStockPayments',
    'PreferredStockIssuance',
    'NetCommonStockIssuance',
    'CommonStockPayments',
    'CommonStockIssuance',
    'NetIssuancePaymentsOfDebt',
    'NetShortTermDebtIssuance',
    'ShortTermDebtPayments',
    'ShortTermDebtIssuance',
    'NetLongTermDebtIssuance',
    'LongTermDebtPayments',
    'LongTermDebtIssuance',
    'InvestingCashFlow',
    'CashFromDiscontinuedInvestingActivities',
    'CashFlowFromContinuingInvestingActivities',
    'NetOtherInvestingChanges',
    'InterestReceivedCFI',
    'DividendsReceivedCFI',
    'NetInvestmentPurchaseAndSale',
    'SaleOfInvestment',
    'PurchaseOfInvestment',
    'NetInvestmentPropertiesPurchaseAndSale',
    'SaleOfInvestmentProperties',
    'PurchaseOfInvestmentProperties',
    'NetBusinessPurchaseAndSale',
    'SaleOfBusiness',
    'PurchaseOfBusiness',
    'NetIntangiblesPurchaseAndSale',
    'SaleOfIntangibles',
    'PurchaseOfIntangibles',
    'NetPPEPurchaseAndSale',
    'SaleOfPPE',
    'PurchaseOfPPE',
    'CapitalExpenditureReported',
    'OperatingCashFlow',
    'CashFromDiscontinuedOperatingActivities',
    'CashFlowFromContinuingOperatingActivities',
    'TaxesRefundPaid',
    'InterestReceivedCFO',
    'InterestPaidCFO',
    'DividendReceivedCFO',
    'DividendPaidCFO',
    'ChangeInWorkingCapital',
    'ChangeInOtherWorkingCapital',
    'ChangeInOtherCurrentLiabilities',
    'ChangeInOtherCurrentAssets',
    'ChangeInPayablesAndAccruedExpense',
    'ChangeInAccruedExpense',
    'ChangeInInterestPayable',
    'ChangeInPayable',
    'ChangeInDividendPayable',
    'ChangeInAccountPayable',
    'ChangeInTaxPayable',
    'ChangeInIncomeTaxPayable',
    'ChangeInPrepaidAssets',
    'ChangeInInventory',
    'ChangeInReceivables',
    'ChangesInAccountReceivables',
    'OtherNonCashItems',
    'ExcessTaxBenefitFromStockBasedCompensation',
    'StockBasedCompensation',
    'UnrealizedGainLossOnInvestmentSecurities',
    'ProvisionandWriteOffofAssets',
    'AssetImpairmentCharge',
    'AmortizationOfSecurities',
    'DeferredTax',
    'DeferredIncomeTax',
    'DepreciationAmortizationDepletion',
    'Depletion',
    'DepreciationAndAmortization',
    'AmortizationCashFlow',
    'AmortizationOfIntangibles',
    'Depreciation',
    'OperatingGainsLosses',
    'PensionAndEmployeeBenefitExpense',
    'EarningsLossesFromEquityInvestments',
    'GainLossOnInvestmentSecurities',
    'NetForeignCurrencyExchangeGainLoss',
    'GainLossOnSaleOfPPE',
    'GainLossOnSaleOfBusiness',
    'NetIncomeFromContinuingOperations',
    'CashFlowsfromusedinOperatingActivitiesDirect',
    'TaxesRefundPaidDirect',
    'InterestReceivedDirect',
    'InterestPaidDirect',
    'DividendsReceivedDirect',
    'DividendsPaidDirect',
    'ClassesofCashPayments',
    'OtherCashPaymentsfromOperatingActivities',
    'PaymentsonBehalfofEmployees',
    'PaymentstoSuppliersforGoodsandServices',
    'ClassesofCashReceiptsfromOperatingActivities',
    'OtherCashReceiptsfromOperatingActivities',
    'ReceiptsfromGovernmentGrants',
    'ReceiptsfromCustomers',
}

OTHER_TYPES_SET = {
    'MarketCap',
    'EnterpriseValue',
    'PeRatio',
    'ForwardPeRatio',
    'PegRatio',
    'PsRatio',
    'PbRatio',
    'EnterprisesValueRevenueRatio',
    'EnterprisesValueEBITDARatio',
    'spEarningsReleaseEvents',
    'analystRatings',
    'economicEvents',
    'earningsConferenceCallEvents',
    'corporateConferenceCallEvents',
    'conferencePresentation',
    'otherCorporate',
    'conferenceEvents',
    'shareHoldersAnnualMeetingsEvents',
    'corporateAnalystMeeting',
    'mergerAndAcquisitionAnnouncement',
}

_TYPES = {
    'income_statement': INCOME_STATEMENT_TYPES_SET,
    'balance_sheet': BALANCE_SHEET_TYPES_SET,
    'cash_flow': CASH_FLOW_TYPES_SET,
    'other': OTHER_TYPES_SET,
}

OTHER_TYPES = ','.join(OTHER_TYPES_SET)

ANNUAL_INCOME_STATEMENT_TYPES_SET = {
    f'annual{typ}' for typ in INCOME_STATEMENT_TYPES_SET
}
ANNUAL_INCOME_STATEMENT_TYPES = ','.join(ANNUAL_INCOME_STATEMENT_TYPES_SET)

QUARTERLY_INCOME_STATEMENT_TYPES_SET = {
    f'quarterly{typ}' for typ in INCOME_STATEMENT_TYPES_SET
}
QUARTERLY_INCOME_STATEMENT_TYPES = ','.join(QUARTERLY_INCOME_STATEMENT_TYPES_SET)

TRAILING_INCOME_STATEMENT_TYPES_SET = {
    f'trailing{typ}' for typ in INCOME_STATEMENT_TYPES_SET
}
TRAILING_INCOME_STATEMENT_TYPES = ','.join(TRAILING_INCOME_STATEMENT_TYPES_SET)

ANNUAL_BALANCE_SHEET_TYPES_SET = {f'annual{typ}' for typ in BALANCE_SHEET_TYPES_SET}
ANNUAL_BALANCE_SHEET_TYPES = ','.join(ANNUAL_BALANCE_SHEET_TYPES_SET)

QUARTERLY_BALANCE_SHEET_TYPES_SET = {
    f'quarterly{typ}' for typ in BALANCE_SHEET_TYPES_SET
}
QUARTERLY_BALANCE_SHEET_TYPES = ','.join(QUARTERLY_BALANCE_SHEET_TYPES_SET)

ANNUAL_CASH_FLOW_TYPES_SET = {f'annual{typ}' for typ in CASH_FLOW_TYPES_SET}
ANNUAL_CASH_FLOW_TYPES = ','.join(ANNUAL_CASH_FLOW_TYPES_SET)

QUARTERLY_CASH_FLOW_TYPES_SET = {f'quarterly{typ}' for typ in CASH_FLOW_TYPES_SET}
QUARTERLY_CASH_FLOW_TYPES = ','.join(QUARTERLY_CASH_FLOW_TYPES_SET)

TRAILING_CASH_FLOW_TYPES_SET = {f'trailing{typ}' for typ in CASH_FLOW_TYPES_SET}
TRAILING_CASH_FLOW_TYPES = ','.join(TRAILING_CASH_FLOW_TYPES_SET)


_ALL_TYPES_SET = (
    ANNUAL_INCOME_STATEMENT_TYPES_SET
    | QUARTERLY_INCOME_STATEMENT_TYPES_SET
    | TRAILING_INCOME_STATEMENT_TYPES_SET
    | ANNUAL_BALANCE_SHEET_TYPES_SET
    | QUARTERLY_BALANCE_SHEET_TYPES_SET
    | ANNUAL_CASH_FLOW_TYPES_SET
    | QUARTERLY_CASH_FLOW_TYPES_SET
    | TRAILING_CASH_FLOW_TYPES_SET
    | OTHER_TYPES_SET
)

_RESULT_KEY_MAP = {
    'get_chart': 'chart',
    'get_quote': 'quoteResponse',
    'get_quote_type': 'quoteType',
    'get_quote_summary': 'quoteSummary',
    'get_timeseries': 'timeseries',
    'get_insights': 'finance',
    'get_recommendations': 'finance',
    'get_options': 'optionChain',
}
