"""Lambda set_not_for_distribution function module.""" from typing import Any from common.connectors.graphql import obo_graphql as graphql from common.schemas.finalize_product import FinalizeProductEvent from common.schemas.ingestion import Event from pydantic import ValidationError import config from src.ingest_app import handle_ingest_event def handle(event: FinalizeProductEvent, context: Any) -> FinalizeProductEvent: graphql.init_graphql_client( environment=config.ENVIRONMENT, service_name=config.M2M_APPLICATION_NAME, graphql_service_name=config.GRAPHQL_SERVICE_NAME, identity_id=str(event.identity_uuid), profile_id=config.PROFILE_ID, profile_type=config.PROFILE_TYPE, headers={ "Correlation-Id": event.correlation_id, "Orchard-Roles": config.ROLE, }, ) graphql.update_product_not_for_distribution(event.product_id, "N") graphql.upsert_bulk_session_ingestion_product( bulk_session_ingestion_id=str(event.bulk_session_ingestion_id), execution_arn=event.execution_arn, product_code=event.product_code, ingestion_status="success", ) return event def handler(event_data: dict[str, Any], context: Any) -> dict[str, Any]: """ Lambda entry point. Args: event_data: Lambda event payload (should look like event.shadow.json) context: Lambda context. """ try: # Attempt to parse event_data as legacy Event first. legacy_event = Event(**event_data) execution_arn = legacy_event.execution_arn correlation_id = legacy_event.correlation_id assert execution_arn legacy_event.product_info = handle_ingest_event( legacy_event.product_info, legacy_event.bulk_session_ingestion_id, execution_arn, correlation_id, legacy_event.identity_uuid, ) return legacy_event.model_dump(mode="json") except ValidationError: event = FinalizeProductEvent(**event_data) return handle(event, context).model_dump(mode="json")