import accloudtant


class UsageRecords(object):
    def __init__(self):
        self._data = []
        self.resources = {}
        self.data_transfers = []

    def __repr__(self):
        return "UsageRecords({})".format(self._data)

    def __getitem__(self, item):
        return self._data[item]

    def append(self, data):
        if data.resource not in self.resources and data.area_id != "":
            self.resources[data.resource] = data.area_id
        if data.area is None and data.resource in self.resources:
            data.area_id = self.resources[data.resource]

        if data.kind.endswith("CloudFront-Out-Bytes"):
            self.data_transfers.append(data)

        self._data.append(data)

    def extend(self, other):
        for data in other._data:
            self.append(data)

    def services(self):
        return set([data.service for data in self._data])

    def areas(self, service):
        return set([data.area for data in self._data if data.service == service])
