import requests

LINKEDIN_API_BASE = "https://api.linkedin.com/v2"


class LinkedInService:
    def __init__(self, access_token):
        self.headers = {
            "Authorization": f"Bearer {access_token}",
            "X-Restli-Protocol-Version": "2.0.0",
            "Content-Type": "application/json",
        }

    def post_job(self, organization_id, job_data):
        url = f"{LINKEDIN_API_BASE}/ugcPosts"
        data = {
            "author": f"urn:li:organization:{organization_id}",
            "lifecycleState": "PUBLISHED",
            "specificContent": {
                "com.linkedin.ugc.ShareContent": {
                    "shareCommentary": {"text": job_data["text"]},
                    "shareMediaCategory": "NONE",
                }
            },
            "visibility": {"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"},
        }
        return requests.post(url, json=data, headers=self.headers)
