from typing import List
from xml.etree import cElementTree as eTree


class MobileProductParser(object):

    def __init__(
        self,
        product_xml: eTree.Element,
        params: List[str],
    ) -> None:

        self.product_code: str
        self.product_name: str
        self.product_qty: str
        self.product_unit: str
        self.product_price: str
        self.product_total_price: str

        self._parse_and_format_params(
            product_xml=product_xml,
            params=params,
        )

    def _parse_and_format_params(
        self,
        product_xml: eTree.Element,
        params: List[str],
    ) -> None:

        self.product_code = product_xml.find(params[0]).text
        self.product_name = product_xml.find(params[1]).text
        self.product_qty = "{:.3f}".format(float(product_xml.find(params[2]).text))
        self.product_unit = product_xml.find(params[3]).text
        self.product_price = "{:.2f}".format(float(product_xml.find(params[4]).text))
        self.product_total_price = "{:.2f}".format(float(product_xml.find(params[5]).text))
