{
  "name": "HR Onboarding Automation",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "manager-form",
        "responseMode": "onReceived",
        "options": {}
      },
      "name": "Manager Form Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const candidateName = $json['candidate_name'];\nconst salary = $json['salary'];\nconst offerText = `Dear ${candidateName},\n\nYou are hired!\n\nHere is your salary: ${salary}\n\nBest regards,\nHR Team`;\n\nreturn [{ json: { offerText } }];"
      },
      "name": "Generate Offer Letter",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "hr@yourcompany.com",
        "toEmail": "={{$json[\"candidate_email\"]}}",
        "subject": "Your Offer Letter",
        "text": "={{$json[\"offerText\"]}}"
      },
      "name": "Send Offer Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        750,
        300
      ],
      "credentials": {
        "smtp": "<your credential>"
      }
    },
    {
      "parameters": {
        "time": 3,
        "unit": "days"
      },
      "name": "Wait for Reply / Signature",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1000,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"signed\"]}}",
              "operation": "equal",
              "value2": true
            }
          ]
        }
      },
      "name": "IF Candidate Signed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1250,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Send to CEO",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1500,
        200
      ],
      "credentials": {
        "smtp": "<your credential>"
      }
    },
    {
      "parameters": {},
      "name": "Send to Payroll",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1750,
        200
      ],
      "credentials": {
        "smtp": "<your credential>"
      }
    },
    {
      "parameters": {
        "model": "gpt-3.5-turbo",
        "messages": [
          {
            "role": "system",
            "content": "You are an HR assistant AI. Candidate questions should be answered using company policy documents in Google Drive. Forward unusual or negotiation-related questions to HR manager."
          },
          {
            "role": "user",
            "content": "Candidate asked: {{$json[\"candidate_question\"]}}"
          }
        ]
      },
      "name": "AI Candidate Response",
      "type": "n8n-nodes-base.openai",
      "typeVersion": 1,
      "position": [
        1500,
        400
      ],
      "credentials": {
        "openAIApi": "<your credential>"
      }
    },
    {
      "parameters": {
        "fromEmail": "hr@yourcompany.com",
        "toEmail": "={{$json[\"candidate_email\"]}}",
        "subject": "Response to your question",
        "text": "={{$json[\"choices\"][0][\"message\"][\"content\"]}}"
      },
      "name": "Send AI Response Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 1,
      "position": [
        1750,
        400
      ],
      "credentials": {
        "smtp": "<your credential>"
      }
    },
    {
      "parameters": {
        "operation": "upload",
        "fileName": "={{$json[\"candidate_name\"] + '_offer.pdf'}}",
        "binaryData": "offerPdf",
        "options": {}
      },
      "name": "Log Document to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 1,
      "position": [
        2000,
        300
      ],
      "credentials": {
        "googleDriveOAuth2Api": "<your credential>"
      }
    }
  ],
  "connections": {
    "Manager Form Trigger": {
      "main": [
        [
          {
            "node": "Generate Offer Letter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Offer Letter": {
      "main": [
        [
          {
            "node": "Send Offer Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Offer Email": {
      "main": [
        [
          {
            "node": "Wait for Reply / Signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Reply / Signature": {
      "main": [
        [
          {
            "node": "IF Candidate Signed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Candidate Signed?": {
      "main": [
        [
          {
            "node": "Send to CEO",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Candidate Response",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Send to CEO": {
      "main": [
        [
          {
            "node": "Send to Payroll",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to Payroll": {
      "main": [
        [
          {
            "node": "Log Document to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Candidate Response": {
      "main": [
        [
          {
            "node": "Send AI Response Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}