from starkcore.utils.resource import Resource
from ..utils import rest


class CorporateBalance(Resource):
    """# CorporateBalance object
    The CorporateBalance object displays the current corporate balance of the Workspace,
    which is the result of the sum of all transactions within this
    Workspace. The balance is never generated by the user, but it
    can be retrieved to see the available information.
    ## Attributes (return-only):
    - id [string]: unique id returned when CorporateBalance is created. ex: "5656565656565656"
    - amount [integer]: current balance amount of the Workspace in cents. ex: 200 (= R$ 2.00)
    - limit [integer]: The maximum negative balance allowed by the user. ex: 10000 (= R$ 100.00)
    - max_limit [integer]: The maximum negative balance allowed by StarkBank. ex: 100000 (= R$ 1000.00)
    - currency [string]: currency of the current Workspace. Expect others to be added eventually. ex: "BRL"
    - updated [datetime.datetime]: latest update datetime for the CorporateBalance. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0)
    """

    def __init__(self, id, amount, limit, max_limit, currency, updated):
        Resource.__init__(self, id=id)

        self.amount = amount
        self.limit = limit
        self.max_limit = max_limit
        self.currency = currency
        self.updated = updated


_resource = {"class": CorporateBalance, "name": "CorporateBalance"}


def get(user=None):
    """# Retrieve the CorporateBalance object
    Receive the CorporateBalance object linked to your Workspace in the Stark Bank API
    ## Parameters (optional):
    - user [Organization/Project object, default None]: Organization or Project object. Not necessary if starkbank.user was set before function call.
    ## Return:
    - CorporateBalance object with updated attributes
    """
    return next(rest.get_stream(resource=_resource, user=user))
