from xml.etree import cElementTree as eTree
from posot import OrderTaker


def set_custom_properties(pos_ot, sale_line, seat, sale_type):
    # type: (OrderTaker, eTree.XML, str, str) -> None

    line_number = sale_line.get("lineNumber")
    part_code = sale_line.get("partCode")

    custom_properties = {}
    if seat and seat != '0':
        custom_properties["seat"] = seat
    if sale_type:
        custom_properties["saleType"] = sale_type

    if len(custom_properties) > 0:
        pos_ot.setOrderCustomProperties(custom_properties, "", line_number, "1", "0", part_code)


def update_or_remove_sale_type(pos_ot, sale_line, sale_type):
    # type: (OrderTaker, eTree.XML, str) -> None

    line_number = sale_line.get("lineNumber")
    part_code = sale_line.get("partCode")

    pos_ot.setOrderCustomProperty("saleType", sale_type, "", line_number, "1", "0", part_code)
