from datetime import datetime
cxFUG=str
cxFUm=int
cxFUp=super
cxFUb=False
cxFUj=isinstance
cxFUz=hash
cxFUV=bool
cxFUB=True
cxFUv=list
cxFUg=map
cxFUW=None
from enum import Enum
from typing import Set
from localstack_ext.bootstrap.cpvcs.constants import(COMMIT_TXT_LAYOUT,REV_TXT_LAYOUT,STATE_TXT_LAYOUT,STATE_TXT_METADATA,VER_TXT_LAYOUT)
from localstack_ext.bootstrap.state_utils import API_STATES_DIR,DYNAMODB_DIR,KINESIS_DIR
class CPVCSObj:
 def __init__(self,hash_ref:cxFUG):
  self.hash_ref:cxFUG=hash_ref
class Serialization(Enum):
 MAIN=API_STATES_DIR
 DDB=DYNAMODB_DIR
 KINESIS=KINESIS_DIR
 serializer_root_lookup={cxFUG(MAIN):API_STATES_DIR,cxFUG(DDB):DYNAMODB_DIR,cxFUG(KINESIS):KINESIS_DIR}
class StateFileRef(CPVCSObj):
 txt_layout=STATE_TXT_LAYOUT
 metadata_layout=STATE_TXT_METADATA
 def __init__(self,hash_ref:cxFUG,rel_path:cxFUG,file_name:cxFUG,size:cxFUm,service:cxFUG,region:cxFUG,serialization:Serialization):
  cxFUp(StateFileRef,self).__init__(hash_ref)
  self.rel_path:cxFUG=rel_path
  self.file_name:cxFUG=file_name
  self.size:cxFUm=size
  self.service:cxFUG=service
  self.region:cxFUG=region
  self.serialization:Serialization=serialization
 def __str__(self):
  return self.txt_layout.format(size=self.size,service=self.service,region=self.region,hash_ref=self.hash_ref,file_name=self.file_name,rel_path=self.rel_path,serialization=self.serialization)
 def __eq__(self,other):
  if not other:
   return cxFUb
  if not cxFUj(other,StateFileRef):
   return cxFUb
  return(self.hash_ref==other.hash_ref and self.region==other.region and self.service==self.service and self.file_name==other.file_name and self.size==other.size)
 def __hash__(self):
  return cxFUz((self.hash_ref,self.region,self.service,self.file_name,self.size))
 def congruent(self,other)->cxFUV:
  if not other:
   return cxFUb
  if not cxFUj(other,StateFileRef):
   return cxFUb
  return(self.region==other.region and self.service==other.service and self.file_name==other.file_name and self.rel_path==other.rel_path)
 def any_congruence(self,others)->cxFUV:
  for other in others:
   if self.congruent(other):
    return cxFUB
  return cxFUb
 def metadata(self)->cxFUG:
  return self.metadata_layout.format(size=self.size,service=self.service,region=self.region)
class CPVCSNode(CPVCSObj):
 def __init__(self,hash_ref:cxFUG,state_files:Set[StateFileRef],parent_ptr:cxFUG):
  cxFUp(CPVCSNode,self).__init__(hash_ref)
  self.state_files:Set[StateFileRef]=state_files
  self.parent_ptr:cxFUG=parent_ptr
 def state_files_info(self)->cxFUG:
  return "\n".join(cxFUv(cxFUg(lambda state_file:cxFUG(state_file),self.state_files)))
class Commit:
 txt_layout=COMMIT_TXT_LAYOUT
 def __init__(self,tail_ptr:cxFUG,head_ptr:cxFUG,message:cxFUG,timestamp:cxFUG=cxFUG(datetime.now().timestamp()),delta_log_ptr:cxFUG=cxFUW):
  self.tail_ptr:cxFUG=tail_ptr
  self.head_ptr:cxFUG=head_ptr
  self.message:cxFUG=message
  self.timestamp:cxFUG=timestamp
  self.delta_log_ptr:cxFUG=delta_log_ptr
 def __str__(self):
  return self.txt_layout.format(tail_ptr=self.tail_ptr,head_ptr=self.head_ptr,message=self.message,timestamp=self.timestamp,log_hash=self.delta_log_ptr)
 def info_str(self,from_node:cxFUG,to_node:cxFUG)->cxFUG:
  return f"from: {from_node}, to: {to_node}, message: {self.message}, time: {datetime.fromtimestamp(float(self.timestamp))}"
class Revision(CPVCSNode):
 txt_layout=REV_TXT_LAYOUT
 def __init__(self,hash_ref:cxFUG,state_files:Set[StateFileRef],parent_ptr:cxFUG,creator:cxFUG,rid:cxFUG,revision_number:cxFUm,assoc_commit:Commit=cxFUW):
  cxFUp(Revision,self).__init__(hash_ref,state_files,parent_ptr)
  self.creator:cxFUG=creator
  self.rid:cxFUG=rid
  self.revision_number:cxFUm=revision_number
  self.assoc_commit=assoc_commit
 def __str__(self):
  return self.txt_layout.format(hash_ref=self.hash_ref,parent=self.parent_ptr,creator=self.creator,rid=self.rid,rev_no=self.revision_number,state_files=";".join(cxFUg(lambda state_file:cxFUG(state_file),self.state_files))if self.state_files else "",assoc_commit=self.assoc_commit)
class Version(CPVCSNode):
 txt_layout=VER_TXT_LAYOUT
 def __init__(self,hash_ref:cxFUG,state_files:Set[StateFileRef],parent_ptr:cxFUG,creator:cxFUG,comment:cxFUG,active_revision_ptr:cxFUG,outgoing_revision_ptrs:Set[cxFUG],incoming_revision_ptr:cxFUG,version_number:cxFUm):
  cxFUp(Version,self).__init__(hash_ref,state_files,parent_ptr)
  self.creator=creator
  self.comment=comment
  self.active_revision_ptr=active_revision_ptr
  self.outgoing_revision_ptrs=outgoing_revision_ptrs
  self.incoming_revision_ptr=incoming_revision_ptr
  self.version_number=version_number
 def __str__(self):
  return VER_TXT_LAYOUT.format(hash_ref=self.hash_ref,parent=self.parent_ptr,creator=self.creator,comment=self.comment,version_number=self.version_number,active_revision=self.active_revision_ptr,outgoing_revisions=";".join(self.outgoing_revision_ptrs),incoming_revision=self.incoming_revision_ptr,state_files=";".join(cxFUg(lambda stat_file:cxFUG(stat_file),self.state_files))if self.state_files else "")
 def info_str(self):
  return f"{self.version_number}, {self.creator}, {self.comment}"
# Created by pyminifier (https://github.com/liftoff/pyminifier)
