#
# This Class contains information for the jpg markers, length, an position in the file
#
class JpgFingerprint:

  def __init__(self):
    self.markers_a    = []
    self.markers_img  = []
    self.markers_meta = []
    # self.markers_h    = {}
    

  def addImgMetadata(self, mhex, mpos, mlen, mstr):
    marker = JpgMarker(mhex, mpos, mlen, mstr)
    self.markers_a.append(marker)
    self.markers_meta.append(marker)

  #
  def addImgData(self, mhex, mpos, mlen, mstr):
    marker = JpgMarker(mhex, mpos, mlen, mstr)
    self.markers_a.append(marker)
    self.markers_img.append(marker)

  #
  def printImgMarkers(self):
    return JpgFingerprint.__printMarker(self.markers_img)

  #
  def printMDMarkers(self):
    return JpgFingerprint.__printMarker(self.markers_meta)

  #
  def __repr__(self):
    return JpgFingerprint.__printMarker(self.markers_a)

  #
  @staticmethod
  def __printMarker(markers):
    str = ""
    total = 0
    for marker in markers:
      str += repr(marker) + "\n"
      total += marker.len
    str += "[TOT ] bytes=={}".format(total)
    str += "\n"
    return str


#
class JpgMarker:
  """
  Marker Data Type
  """
  def __init__(self, mhex, fpos, mlen, mstr):
    self.hex     = mhex
    self.hexstr  = self.hex.to_bytes(2, 'big').hex()
    self.fpos    = fpos
    self.len     = mlen
    self.type    = mstr

  #
  def __repr__(self):
    return "[{}] {} {}(len) {}(fpos)".format(self.type, self.hexstr, self.len, self.fpos)

