{
  "name": "HireMind - Application Approval & Auto-Apply Handler",
  "description": "Handles user approval of jobs and automatically applies on behalf of user",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "approve-applications",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "approval-webhook",
      "name": "User Approval Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "userId",
              "value": "={{ $json.body.userId }}"
            },
            {
              "name": "userEmail",
              "value": "={{ $json.body.userEmail }}"
            },
            {
              "name": "approved",
              "value": "={{ $json.body.approved }}"
            },
            {
              "name": "selectedJobs",
              "value": "={{ JSON.stringify($json.body.selectedJobs) }}"
            }
          ]
        }
      },
      "id": "extract-approval-data",
      "name": "Extract Approval Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        470,
        300
      ]
    },
    {
      "parameters": {
        "value": "={{ $json.approved === true && $json.selectedJobs.length > 0 }}"
      },
      "id": "check-approved",
      "name": "Check Approval Status",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        690,
        300
      ]
    },
    {
      "parameters": {
        "loopMode": "items",
        "OG_node_title": "Loop Over Jobs"
      },
      "id": "loop-jobs",
      "name": "Loop Over Jobs",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2,
      "position": [
        910,
        200
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "jobId",
              "value": "={{ $json.jobId }}"
            },
            {
              "name": "jobTitle",
              "value": "={{ $json.jobTitle }}"
            },
            {
              "name": "company",
              "value": "={{ $json.company }}"
            },
            {
              "name": "jobUrl",
              "value": "={{ $json.jobUrl }}"
            }
          ]
        }
      },
      "id": "prepare-job-data",
      "name": "Prepare Job Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1130,
        200
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3000/api/applications/generate-cover-letter",
        "method": "POST",
        "authentication": "none",
        "sendData": "body",
        "specifyBody": "json",
        "jsonBody": "{\n  \"jobId\": \"={{ $json.jobId }}\",\n  \"userId\": \"={{ $json.userId }}\",\n  \"jobTitle\": \"={{ $json.jobTitle }}\",\n  \"company\": \"={{ $json.company }}\"\n}"
      },
      "id": "generate-cover-letter",
      "name": "Generate Cover Letter",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1350,
        200
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3000/api/applications/submit",
        "method": "POST",
        "authentication": "none",
        "sendData": "body",
        "specifyBody": "json",
        "jsonBody": "{\n  \"userId\": \"={{ $json.userId }}\",\n  \"jobId\": \"={{ $json.jobId }}\",\n  \"jobTitle\": \"={{ $json.jobTitle }}\",\n  \"company\": \"={{ $json.company }}\",\n  \"coverLetter\": \"={{ $json.body.coverLetter }}\",\n  \"status\": \"applied\",\n  \"appliedDate\": \"={{ new Date().toISOString() }}\"\n}"
      },
      "id": "submit-application",
      "name": "Submit Application",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1570,
        200
      ]
    },
    {
      "parameters": {
        "subject": "Application Submitted - {{ $json.jobTitle }} at {{ $json.company }}",
        "fromEmail": "hiremindagent@gmail.com",
        "toEmail": "={{ $json.userEmail }}",
        "htmlBody": "<h3>Application Submitted Successfully! \u2705</h3>\n<p><strong>Position:</strong> {{ $json.jobTitle }}</p>\n<p><strong>Company:</strong> {{ $json.company }}</p>\n<p><strong>Applied Date:</strong> {{ new Date().toLocaleDateString() }}</p>\n<p>We'll monitor this application and notify you of any updates!</p>\n<p><a href=\"http://localhost:3000/dashboard/tracker\">View in Dashboard</a></p>",
        "authentication": "gmail",
        "emailPassword": "dltz rdmm hibq zbbk"
      },
      "id": "send-app-confirm-email",
      "name": "Send Application Confirmation Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1790,
        200
      ]
    },
    {
      "parameters": {
        "subject": "Application Rejected - {{ $json.jobTitle }} at {{ $json.company }}",
        "fromEmail": "hiremindagent@gmail.com",
        "toEmail": "={{ $json.userEmail }}",
        "htmlBody": "<h3>Application Status - Rejected</h3>\n<p><strong>Position:</strong> {{ $json.jobTitle }}</p>\n<p><strong>Company:</strong> {{ $json.company }}</p>\n<p>Unfortunately, your application was not moved forward at this time.</p>\n<p>Don't worry! We're finding more opportunities for you.</p>\n<p><a href=\"http://localhost:3000/dashboard\">View All Opportunities</a></p>",
        "authentication": "gmail",
        "emailPassword": "dltz rdmm hibq zbbk"
      },
      "id": "send-rejection-email",
      "name": "Send Rejection Notification",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1790,
        400
      ]
    },
    {
      "parameters": {
        "subject": "HireMind - Approval Declined",
        "fromEmail": "hiremindagent@gmail.com",
        "toEmail": "={{ $json.userEmail }}",
        "htmlBody": "<h2>No Jobs Approved</h2>\n<p>It looks like you declined the job applications we found for you.</p>\n<p>You can come back anytime to discover more opportunities or adjust your preferences.</p>\n<p><a href=\"http://localhost:3000/dashboard\">Return to Dashboard</a></p>"
      },
      "id": "send-decline-email",
      "name": "Send Decline Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        910,
        500
      ]
    }
  ],
  "connections": {
    "approval-webhook": {
      "main": [
        [
          {
            "node": "extract-approval-data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extract-approval-data": {
      "main": [
        [
          {
            "node": "check-approved",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check-approved": {
      "main": [
        [
          {
            "node": "loop-jobs",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "send-decline-email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "loop-jobs": {
      "main": [
        [
          {
            "node": "prepare-job-data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "prepare-job-data": {
      "main": [
        [
          {
            "node": "generate-cover-letter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generate-cover-letter": {
      "main": [
        [
          {
            "node": "submit-application",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "submit-application": {
      "main": [
        [
          {
            "node": "send-app-confirm-email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true
}