{
  "packageType": "ControlCenterPowerAutomateBlueprint",
  "solution": "Control Center - Order Tech - Notificaciones",
  "version": "2.0.0",
  "description": "Blueprint del flujo HTTP que recibe notificaciones de atrasos desde Control Center y envía correo mediante Office 365 Outlook.",
  "importability": {
    "directImport": false,
    "reason": "Power Automate exige crear o importar el flujo dentro del tenant y seleccionar una conexión de Office 365 Outlook perteneciente al entorno.",
    "estimatedSetupMinutes": 10
  },
  "requirements": {
    "license": "Power Automate con conector Office 365 Outlook",
    "connection": "Office 365 Outlook",
    "recommendedOwner": "Cuenta de servicio administrada por Order Latam",
    "controlCenterUrl": "https://controlcenter.orderlatam.com"
  },
  "flow": {
    "displayName": "Control Center - Enviar notificación por correo",
    "trigger": {
      "connector": "Request",
      "operation": "When an HTTP request is received",
      "method": "POST",
      "requestBodySchema": {
        "type": "object",
        "required": ["to", "subject", "html"],
        "properties": {
          "to": { "type": "string", "description": "Destinatarios separados por punto y coma" },
          "cc": { "type": "string" },
          "subject": { "type": "string" },
          "html": { "type": "string" },
          "metadata": {
            "type": "object",
            "properties": {
              "commitmentId": { "type": "string" },
              "project": { "type": "string" },
              "daysOverdue": { "type": "integer" },
              "stage": { "type": "string" },
              "generatedAt": { "type": "string" }
            }
          }
        }
      }
    },
    "actions": [
      {
        "order": 1,
        "name": "Validar destinatario",
        "type": "Condition",
        "expression": "@not(empty(triggerBody()?['to']))",
        "ifFalse": { "action": "Response", "statusCode": 400, "body": { "ok": false, "message": "Destinatario requerido" } }
      },
      {
        "order": 2,
        "name": "Enviar correo (V2)",
        "connector": "Office 365 Outlook",
        "operationId": "SendEmailV2",
        "parameters": {
          "To": "@triggerBody()?['to']",
          "Cc": "@triggerBody()?['cc']",
          "Subject": "@triggerBody()?['subject']",
          "Body": "@triggerBody()?['html']",
          "Importance": "@if(equals(triggerBody()?['metadata']?['stage'],'gerencia'),'High','Normal')"
        }
      },
      {
        "order": 3,
        "name": "Responder a Control Center",
        "type": "Response",
        "statusCode": 200,
        "body": {
          "ok": true,
          "commitmentId": "@triggerBody()?['metadata']?['commitmentId']",
          "sentAt": "@utcNow()"
        }
      }
    ],
    "errorHandling": {
      "runAfter": ["Enviar correo (V2): Failed", "Enviar correo (V2): TimedOut"],
      "response": {
        "statusCode": 500,
        "body": { "ok": false, "message": "No fue posible enviar el correo", "flowRun": "@workflow()?['run']?['name']" }
      }
    }
  },
  "powerAutomateDefinitionReference": {
    "$schema": "https://schema.management.azure.com/schemas/2016-06-01/workflowdefinition.json#",
    "contentVersion": "1.0.0.0",
    "triggers": {
      "When_an_HTTP_request_is_received": {
        "type": "Request",
        "kind": "Http",
        "inputs": {
          "schema": {
            "type": "object",
            "required": ["to", "subject", "html"],
            "properties": {
              "to": { "type": "string" },
              "cc": { "type": "string" },
              "subject": { "type": "string" },
              "html": { "type": "string" },
              "metadata": { "type": "object" }
            }
          }
        }
      }
    },
    "actions": {
      "Send_an_email_(V2)": {
        "type": "OpenApiConnection",
        "inputs": {
          "host": {
            "apiId": "/providers/Microsoft.PowerApps/apis/shared_office365",
            "connection": "shared_office365",
            "operationId": "SendEmailV2"
          },
          "parameters": {
            "emailMessage/To": "@triggerBody()?['to']",
            "emailMessage/Cc": "@triggerBody()?['cc']",
            "emailMessage/Subject": "@triggerBody()?['subject']",
            "emailMessage/Body": "@triggerBody()?['html']",
            "emailMessage/Importance": "@if(equals(triggerBody()?['metadata']?['stage'],'gerencia'),'High','Normal')"
          }
        },
        "runAfter": {}
      },
      "Response": {
        "type": "Response",
        "kind": "Http",
        "inputs": {
          "statusCode": 200,
          "body": {
            "ok": true,
            "commitmentId": "@triggerBody()?['metadata']?['commitmentId']",
            "sentAt": "@utcNow()"
          }
        },
        "runAfter": { "Send_an_email_(V2)": ["Succeeded"] }
      }
    }
  },
  "setup": [
    "En Power Automate, crear un Flujo de nube instantáneo.",
    "Seleccionar el disparador Cuando se recibe una solicitud HTTP.",
    "Copiar requestBodySchema en el esquema JSON del disparador.",
    "Agregar Office 365 Outlook - Enviar un correo electrónico (V2).",
    "Asignar To, Cc, Subject y Body usando las expresiones indicadas.",
    "Agregar una acción Respuesta con HTTP 200 después del envío.",
    "Guardar el flujo y copiar la URL HTTP generada.",
    "En Control Center abrir Notificaciones, pegar la URL, activar envíos y guardar.",
    "Usar Probar detección ahora y verificar el historial."
  ],
  "security": [
    "Tratar la URL HTTP del flujo como un secreto.",
    "Usar una cuenta de servicio con propietario alterno.",
    "Aplicar DLP del entorno y limitar el flujo al tenant Order Latam."
  ],
  "acceptance": [
    "Control Center recibe HTTP 200.",
    "El correo llega al responsable correcto.",
    "El HTML corporativo se renderiza correctamente.",
    "No se envía más de un correo por compromiso, etapa y día.",
    "Los errores quedan visibles en el historial del Control Center."
  ]
}
