from datetime import datetime
from xml.etree.ElementTree import Element

import iso8601
from ._BaseLoyaltyCoupon import BaseLoyaltyCoupon


class LoyaltyCouponNfceBuilder(BaseLoyaltyCoupon):


    def get_fiscal_key(self, fiscal_xml: Element) -> str:
        return fiscal_xml.find(".//infNFe").attrib["Id"][3:]

    def get_fiscal_date(self, fiscal_xml: Element) -> datetime:
        return iso8601.parse_date(fiscal_xml.find(".//dhEmi").text)
