""" functions to fetch dta from other services"""
from django.db import  connection
from rest_framework.exceptions import NotFound


def get_customer_requirement_data(ship_to):
    """function to user_details"""
    try:
        with connection.cursor() as cursor:
            cursor.execute("""
                SELECT 
                            IsSample, IsContainerRequired, IsOutSideEU, NoCustomerEmailRequired,
                            NeedReturnMDGD, NeedVGM, SendLoadReferenceToTransporter
                FROM CustomerRequirements where ShipTo=%s
            """, [
                ship_to
            ])
            requirement_data = cursor.fetchone()
            
    except Exception as e:
        raise NotFound({
            "status_code": 500,
            "status": "error",
            "message": f"Requirements not found details not found: {str(e)}",
            "data": None
        })
    if requirement_data:
        return {
            'is_sample': requirement_data[0],
            'is_container': requirement_data[1],
            'is_outside_eu': requirement_data[2],
            'confirmation_mail_not_required': requirement_data[3],
            'return_mdgd': requirement_data[4], 
            'vgm': requirement_data[5], 
            'load_reference': requirement_data[6], 
        }
    else:
        return None
    

