#test přístupu do eReceptu
# erecept_poc.py
import os
from requests import Session
from requests_pkcs12 import Pkcs12Adapter
from zeep import Client
from zeep.transports import Transport

PFX_FILE = "../AMBSUKL214235369G_31DEC2024.pfx"
PFX_PASSWORD = os.getenv("Vlado7309208104++", "")  # nebo zadejte přímo jako řetězec
# WSDL_URL = "https://<ERECEPT_ENDPOINT>/path?wsdl"  # doplňte
WSDL_URL = "https://lekar-soap.erecept.sukl.cz/cuer/Lekar?wsdl"  # doplňte

# Session s PFX (obstará klientskou autentizaci mTLS) https://lekar-soap.erecept.sukl.cz/cuer/Lekar?wsdl
sess = Session()
sess.mount("https://", Pkcs12Adapter(pkcs12_filename=PFX_FILE, pkcs12_password=PFX_PASSWORD))

# zeep klient s naší session
transport = Transport(session=sess, timeout=30)
client = Client(wsdl=WSDL_URL, transport=transport)

# Pro kontrolu: vylistuj dostupné služby a operace
for service in client.wsdl.services.values():
    print(f"Service: {service.name}")
    for port in service.ports.values():
        ops = sorted(port.binding._operations.values(), key=lambda o: o.name)
        print(f"  Port: {port.name}")
        for op in ops:
            print(f"    Operation: {op.name}")

# Příklad volání (názvy/parametry dle WSDL):
# headers = {"UserID": "...", "WorkplaceID": "..."}  # ilustrativní
# resp = client.service.NazevOperace(requestPayload, _soapheaders=headers)
# print(resp)
