### Step 1: Create Django project and app
# Run these commands in terminal
# django-admin startproject hospital_recruitment
# cd hospital_recruitment
# python manage.py startapp recruitment

# Step 2: settings.py (Partial - Key Setup)
# Add to INSTALLED_APPS
INSTALLED_APPS = [
    ...,
    'rest_framework',
    'recruitment',
    'corsheaders',
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.linkedin_oauth2',
]

SITE_ID = 1

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
]

# Middleware
MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    ...
]

CORS_ALLOW_ALL_ORIGINS = True

# LinkedIn OAuth Config
SOCIALACCOUNT_PROVIDERS = {
    'linkedin_oauth2': {
        'SCOPE': [
            'r_liteprofile', 'r_emailaddress', 'w_member_social',
            'rw_organization_admin', 'w_organization_social'
        ],
        'PROFILE_FIELDS': [
            'id', 'first-name', 'last-name', 'email-address'
        ]
    }
}

# Step 3: recruitment/models.py
from django.db import models
from django.contrib.auth.models import User, Group



# Step 4: recruitment/views.py


# Step 5: recruitment/serializers.py


# Step 6: urls.py (project level)


# Step 7: LinkedIn Integration Utility (recruitment/linkedin.py)


# Step 8: Resume Parsing with spaCy (recruitment/utils/resume_parser.py)
import spacy

def extract_summary(text):
    nlp = spacy.load("en_core_web_sm")
    doc = nlp(text)
    summary = {
        'name': doc.ents[0].text if doc.ents else '',
        'skills': [chunk.text for chunk in doc.noun_chunks if len(chunk.text.split()) > 1],
        'summary': text[:500]
    }
    return summary

# Step 9: Zoom API Integration Helper (recruitment/zoom_api.py)
import requests
import jwt
import time

ZOOM_API_KEY = 'your_zoom_api_key'
ZOOM_API_SECRET = 'your_zoom_api_secret'

def generate_zoom_jwt():
    payload = {
        'iss': ZOOM_API_KEY,
        'exp': time.time() + 3600
    }
    token = jwt.encode(payload, ZOOM_API_SECRET, algorithm='HS256')
    return token

def create_zoom_meeting(topic, start_time, duration, host_email):
    jwt_token = generate_zoom_jwt()
    headers = {
        'Authorization': f'Bearer {jwt_token}',
        'Content-Type': 'application/json'
    }
    data = {
        "topic": topic,
        "type": 2,
        "start_time": start_time,
        "duration": duration,
        "schedule_for": host_email,
        "settings": {"join_before_host": True}
    }
    url = f"https://api.zoom.us/v2/users/{host_email}/meetings"
    return requests.post(url, json=data, headers=headers)

# Step 10: Frontend Page Builder (Using GrapesJS embedded view)
# In template: recruitment/templates/page_builder.html
#
# <iframe src="https://grapesjs.com/demo.html" width="100%" height="700px" frameborder="0"></iframe>
#
# Later integrate with Django admin to save generated HTML to JobPage model

# Step 11: Analytics Dashboard (recruitment/dashboard.py)
import pandas as pd
from .models import Candidate

def get_dashboard_data():
    df = pd.DataFrame(list(Candidate.objects.all().values('status', 'created_at')))
    summary = df['status'].value_counts().to_dict()
    return summary

# Step 12: Real-time Updates (via Django Channels)
# Install Django Channels and Redis
# Configure WebSocket routing for job/candidate status updates
# Use channels to broadcast status updates to HR dashboard

# Step 13: Role-Based Access Control
# Use Django Groups: Admin, Recruiter, Interviewer
# Assign permissions using Django admin or programmatically

# Step 14: Candidate Database UI
# Extend CandidateViewSet with filters for name, email, job, date
# Add search + filter UI in frontend (Django or React-based UI)

# Ready to build templates, JavaScript frontend, and training module upon request
