def getAllTransactions(userId):
    return f"""SELECT * FROM transactions T, portfolios P
               WHERE T.portfolio_uuid = P.uuid
               AND P.user_uuid = '{userId}';"""


def getTransactionsByPortfolioId(portfolioId):
    return f"""SELECT  * FROM transactions T
               WHERE '{portfolioId}' = T.portfolio_uuid;"""


def insertTransaction(portfolioId, transaction):
    if transaction['type'] == 'withdrawal':
        transaction['value'] = -1 * abs(transaction['value'])

    return f"""CALL processNewTransaction('{portfolioId}', {transaction['value']}, '{transaction['bank_account']}',
               '{transaction['description']}');"""


def countTransactions():
    return f"SELECT COUNT(*) FROM transactions;"

def getAllTransactions(userId):
    return f"""SELECT * FROM transactions T, portfolios P
               WHERE T.portfolio_uuid = P.uuid
               AND P.user_uuid = '{userId}';"""


def getTransactionsByPortfolioId(portfolioId):
    return f"""SELECT  * FROM transactions T
               WHERE '{portfolioId}' = T.portfolio_uuid;"""


def insertTransaction(portfolioId, transaction):
    if transaction['type'] == 'withdrawal':
        transaction['value'] = -1 * abs(transaction['value'])

    return f"""CALL processNewTransaction('{portfolioId}', {transaction['value']}, '{transaction['bank_account']}',
               '{transaction['description']}');"""


def countTransactions():
    return f"SELECT COUNT(*) FROM transactions;"

SELECT * FROM transactions T, portfolios P                WHERE T.portfolio_uuid = P.uuid                AND P.user_uuid = '{userId}'; SELECT  * FROM transactions T                WHERE '{portfolioId}' = T.portfolio_uuid; CALL processNewTransaction('{portfolioId}', {transaction['value']}, '{transaction['bank_account']}',                '{transaction['description']}');