# Path: flask_github/client/messages.py
# class Tree(msgs.Message):
#   url = msgs.StringField(1)
#   sha = msgs.StringField(2)
#   message = msgs.StringField(3)
#   tree = msgs.MessageField('Tree', 4, repeated=True)
#   # fields that live on the tree api responses..
#   path = msgs.StringField(5)
#   mode = msgs.StringField(6)
#   type = msgs.StringField(7)
#   size = msgs.IntegerField(8, default=0)
#   content = msgs.StringField(9)
#   # String of the SHA1 of the tree you want to update with new data
#   base_tree = msgs.StringField(10)
# 
# Path: flask_github/client/requests.py
# class TreeResponse(msgs.Message):
#   response = msgs.MessageField('Tree', 1)
# 
# Path: flask_github/client/requests.py
# class TreeListResponse(msgs.Message):
#   response = msgs.MessageField('Tree', 1, repeated=True)


from ..messages import Tree
from ..requests import TreeResponse
from ..requests import TreeListResponse

from __future__ import unicode_literals

class GitDataTrees:
  def __init__(self, client):
    self.client = client

  def get(self, repo, sha, recursive=False, user=None):
    query = None
    if recursive:
      query = {'recursive': '1'}
    return self.client.get('repos/%s/%s/git/trees/%s' % (
      self.client.user(user), repo, sha), query=query, msg_type=TreeListResponse)

  def create(self, repo, tree, base_tree=None, user=None):
    msg = Tree(
      base_tree=base_tree,
      tree=tree)
    return self._create(repo=repo, msg=msg, user=user)

  def _create(self, repo, msg, user=None):
    return self.client.post(
      'repos/%s/%s/git/trees' % (

# Path: flask_github/client/messages.py
# class Tree(msgs.Message):
#   url = msgs.StringField(1)
#   sha = msgs.StringField(2)
#   message = msgs.StringField(3)
#   tree = msgs.MessageField('Tree', 4, repeated=True)
#   # fields that live on the tree api responses..
#   path = msgs.StringField(5)
#   mode = msgs.StringField(6)
#   type = msgs.StringField(7)
#   size = msgs.IntegerField(8, default=0)
#   content = msgs.StringField(9)
#   # String of the SHA1 of the tree you want to update with new data
#   base_tree = msgs.StringField(10)
# 
# Path: flask_github/client/requests.py
# class TreeResponse(msgs.Message):
#   response = msgs.MessageField('Tree', 1)
# 
# Path: flask_github/client/requests.py
# class TreeListResponse(msgs.Message):
#   response = msgs.MessageField('Tree', 1, repeated=True)


# Path: flask_github/client/gitdata/gitdatatrees.py
from ..messages import Tree
from ..requests import TreeResponse
from ..requests import TreeListResponse

from __future__ import unicode_literals

class GitDataTrees:
  def __init__(self, client):
    self.client = client

  def get(self, repo, sha, recursive=False, user=None):
    query = None
    if recursive:
      query = {'recursive': '1'}
    return self.client.get('repos/%s/%s/git/trees/%s' % (
      self.client.user(user), repo, sha), query=query, msg_type=TreeListResponse)

  def create(self, repo, tree, base_tree=None, user=None):
    msg = Tree(
      base_tree=base_tree,
      tree=tree)
    return self._create(repo=repo, msg=msg, user=user)

  def _create(self, repo, msg, user=None):
    return self.client.post(
      'repos/%s/%s/git/trees' % (

        self.client.user(user), repo), data=msg, msg_type=TreeResponse)
