""" functions to fetch dta from other services"""

from rest_framework.exceptions import ValidationError, NotFound
from django.db import  connection

def get_address_data(address_id):
    """function to user_details"""
    try:
        with connection.cursor() as cursor:
            cursor.execute("""
                SELECT Id, ExactERPAddressId, CustomerName, City, AddressLine1, AddressLine2, AddressLine3, PostalCode
                  from AddressMaster where Id=%s
            """, [
                address_id
            ])
            user_data = cursor.fetchone()
            
    except Exception as e:
        raise NotFound({
            "status_code": 500,
            "status": "error",
            "message": f"User details not found: {str(e)}",
            "data": None
        })
    if user_data:
        return {
            'Id': user_data[0], 
            'exact_erp_address_id': user_data[1],
            'customer_name': user_data[2],
            'city': user_data[3],
            'addressline1': user_data[4],
            'addressline2': user_data[5],
            'addressline3': user_data[6],
            'postal_code': user_data[7],
            }
    else:
        return None