# Path: amdeb_amazon/model_names/shared_names.py
# MODEL_NAME_FIELD = 'model_name'
# 
# RECORD_ID_FIELD = 'record_id'
# 
# TEMPLATE_ID_FIELD = 'template_id'
# 
# PRODUCT_SKU_FIELD = 'product_sku'
# 
# WRITE_FIELD_NAMES_FIELD = 'write_field_names'
# 
# Path: amdeb_amazon/model_names/product_sync.py
# AMAZON_PRODUCT_SYNC_TABLE = 'amdeb.amazon.product.sync'
# 
# SYNC_TYPE_FIELD = 'sync_type'
# 
# SYNC_STATUS_FIELD = 'sync_status'
# 
# SYNC_CHECK_STATUS_COUNT_FILED = 'sync_check_status_count'
# 
# AMAZON_MESSAGE_CODE_FIELD = 'amazon_message_code'
# 
# AMAZON_RESULT_DESCRIPTION_FIELD = 'amazon_result_description'
# 
# AMAZON_REQUEST_TIMESTAMP_FIELD = 'amazon_request_timestamp'
# 
# SYNC_DELETE = 'sync_delete'
# 
# SYNC_STATUS_NEW = 'New'
# 
# SYNC_STATUS_PENDING = 'Pending'
# 
# SYNC_STATUS_ERROR = 'Error'
# 
# AMAZON_STATUS_PROCESS_DONE = '_DONE_'
# 
# SYNC_STATUS_SUCCESS = 'Success'
# 
# SYNC_STATUS_WAITING = 'Waiting'
# 
# Path: amdeb_amazon/shared/utility.py
# def field_utcnow(*args):
#     """ Return the current UTC day and time in the format expected by the ORM.
#         This function may be used to compute default values.
#     """
#     return datetime.utcnow().strftime(DATETIME_FORMAT)
# 
# Path: amdeb_amazon/models_access/sync_head_access.py
# class SyncHeadAccess(object):
#     """
#     The base class used to define common methods for
#     sync head fields thus each sync_head can use its own access class.
#     """
#     @staticmethod
#     def is_product_template(sync_head):
#         return sync_head[MODEL_NAME_FIELD] == PRODUCT_TEMPLATE_TABLE
# 
#     @staticmethod
#     def is_product_variant(sync_head):
#         return sync_head[MODEL_NAME_FIELD] == PRODUCT_PRODUCT_TABLE
# 
#     @staticmethod
#     def get_write_field_names(sync_head):
#         field_names = sync_head[WRITE_FIELD_NAMES_FIELD]
#         if field_names:
#             data = set(field_names.split(FIELD_NAME_DELIMITER))
#         else:
#             data = set()
#         return data
# 
#     @staticmethod
#     def save_write_field_names(sync_head, write_fields):
#         joined = FIELD_NAME_DELIMITER.join(write_fields)
#         sync_head[WRITE_FIELD_NAMES_FIELD] = joined


import logging
from ..model_names.shared_names import (
    MODEL_NAME_FIELD, RECORD_ID_FIELD,
    TEMPLATE_ID_FIELD, PRODUCT_SKU_FIELD,
    WRITE_FIELD_NAMES_FIELD,
)
from ..model_names.product_sync import (
    AMAZON_PRODUCT_SYNC_TABLE,
    SYNC_TYPE_FIELD,
    SYNC_STATUS_FIELD,
    SYNC_CHECK_STATUS_COUNT_FILED,
    AMAZON_MESSAGE_CODE_FIELD,
    AMAZON_RESULT_DESCRIPTION_FIELD,
    AMAZON_REQUEST_TIMESTAMP_FIELD,
    SYNC_DELETE,
    SYNC_STATUS_NEW, SYNC_STATUS_PENDING,
    SYNC_STATUS_ERROR, AMAZON_STATUS_PROCESS_DONE,
    SYNC_STATUS_SUCCESS, SYNC_STATUS_WAITING,
)
from ..shared.utility import field_utcnow
from .sync_head_access import SyncHeadAccess
    The sync_head is an object that defines model_name,
    record_id and template_id. It could be a product operation record
    or an Amazon sync record
    """
    def __init__(self, env):
        self._table = env[AMAZON_PRODUCT_SYNC_TABLE]

    @staticmethod
    def _log_values(values):
        log_template = "Create new sync record for Model: {0}, " \
                       "record id: {1}, sync type: {2}, " \
                       "write fields: {3}, product sku: {4}, " \
                       "waiting flag: {5}, error_flag: {6}."
        _logger.debug(log_template.format(
            values[MODEL_NAME_FIELD],
            values[RECORD_ID_FIELD],
            values[SYNC_TYPE_FIELD],
            values.get(WRITE_FIELD_NAMES_FIELD, None),
            values.get(PRODUCT_SKU_FIELD, None),
            values.get(SYNC_STATUS_FIELD, None),
            values.get(AMAZON_MESSAGE_CODE_FIELD, None),
        ))

    def insert_sync(self, sync_head, sync_type,
                    write_field_names=None, product_sku=None,
                    waiting_flag=None, error_flag=None):
        """
        Insert a new sync operation record.
        """
        values = {

# Path: amdeb_amazon/model_names/shared_names.py
# MODEL_NAME_FIELD = 'model_name'
# 
# RECORD_ID_FIELD = 'record_id'
# 
# TEMPLATE_ID_FIELD = 'template_id'
# 
# PRODUCT_SKU_FIELD = 'product_sku'
# 
# WRITE_FIELD_NAMES_FIELD = 'write_field_names'
# 
# Path: amdeb_amazon/model_names/product_sync.py
# AMAZON_PRODUCT_SYNC_TABLE = 'amdeb.amazon.product.sync'
# 
# SYNC_TYPE_FIELD = 'sync_type'
# 
# SYNC_STATUS_FIELD = 'sync_status'
# 
# SYNC_CHECK_STATUS_COUNT_FILED = 'sync_check_status_count'
# 
# AMAZON_MESSAGE_CODE_FIELD = 'amazon_message_code'
# 
# AMAZON_RESULT_DESCRIPTION_FIELD = 'amazon_result_description'
# 
# AMAZON_REQUEST_TIMESTAMP_FIELD = 'amazon_request_timestamp'
# 
# SYNC_DELETE = 'sync_delete'
# 
# SYNC_STATUS_NEW = 'New'
# 
# SYNC_STATUS_PENDING = 'Pending'
# 
# SYNC_STATUS_ERROR = 'Error'
# 
# AMAZON_STATUS_PROCESS_DONE = '_DONE_'
# 
# SYNC_STATUS_SUCCESS = 'Success'
# 
# SYNC_STATUS_WAITING = 'Waiting'
# 
# Path: amdeb_amazon/shared/utility.py
# def field_utcnow(*args):
#     """ Return the current UTC day and time in the format expected by the ORM.
#         This function may be used to compute default values.
#     """
#     return datetime.utcnow().strftime(DATETIME_FORMAT)
# 
# Path: amdeb_amazon/models_access/sync_head_access.py
# class SyncHeadAccess(object):
#     """
#     The base class used to define common methods for
#     sync head fields thus each sync_head can use its own access class.
#     """
#     @staticmethod
#     def is_product_template(sync_head):
#         return sync_head[MODEL_NAME_FIELD] == PRODUCT_TEMPLATE_TABLE
# 
#     @staticmethod
#     def is_product_variant(sync_head):
#         return sync_head[MODEL_NAME_FIELD] == PRODUCT_PRODUCT_TABLE
# 
#     @staticmethod
#     def get_write_field_names(sync_head):
#         field_names = sync_head[WRITE_FIELD_NAMES_FIELD]
#         if field_names:
#             data = set(field_names.split(FIELD_NAME_DELIMITER))
#         else:
#             data = set()
#         return data
# 
#     @staticmethod
#     def save_write_field_names(sync_head, write_fields):
#         joined = FIELD_NAME_DELIMITER.join(write_fields)
#         sync_head[WRITE_FIELD_NAMES_FIELD] = joined


# Path: amdeb_amazon/models_access/product_sync_access.py
import logging
from ..model_names.shared_names import (
    MODEL_NAME_FIELD, RECORD_ID_FIELD,
    TEMPLATE_ID_FIELD, PRODUCT_SKU_FIELD,
    WRITE_FIELD_NAMES_FIELD,
)
from ..model_names.product_sync import (
    AMAZON_PRODUCT_SYNC_TABLE,
    SYNC_TYPE_FIELD,
    SYNC_STATUS_FIELD,
    SYNC_CHECK_STATUS_COUNT_FILED,
    AMAZON_MESSAGE_CODE_FIELD,
    AMAZON_RESULT_DESCRIPTION_FIELD,
    AMAZON_REQUEST_TIMESTAMP_FIELD,
    SYNC_DELETE,
    SYNC_STATUS_NEW, SYNC_STATUS_PENDING,
    SYNC_STATUS_ERROR, AMAZON_STATUS_PROCESS_DONE,
    SYNC_STATUS_SUCCESS, SYNC_STATUS_WAITING,
)
from ..shared.utility import field_utcnow
from .sync_head_access import SyncHeadAccess

    The sync_head is an object that defines model_name,
    record_id and template_id. It could be a product operation record
    or an Amazon sync record
    """
    def __init__(self, env):
        self._table = env[AMAZON_PRODUCT_SYNC_TABLE]

    @staticmethod
    def _log_values(values):
        log_template = "Create new sync record for Model: {0}, " \
                       "record id: {1}, sync type: {2}, " \
                       "write fields: {3}, product sku: {4}, " \
                       "waiting flag: {5}, error_flag: {6}."
        _logger.debug(log_template.format(
            values[MODEL_NAME_FIELD],
            values[RECORD_ID_FIELD],
            values[SYNC_TYPE_FIELD],
            values.get(WRITE_FIELD_NAMES_FIELD, None),
            values.get(PRODUCT_SKU_FIELD, None),
            values.get(SYNC_STATUS_FIELD, None),
            values.get(AMAZON_MESSAGE_CODE_FIELD, None),
        ))

    def insert_sync(self, sync_head, sync_type,
                    write_field_names=None, product_sku=None,
                    waiting_flag=None, error_flag=None):
        """
        Insert a new sync operation record.
        """
        values = {

            MODEL_NAME_FIELD: sync_head[MODEL_NAME_FIELD],