import re
from typing import Optional
from pydantic import BaseModel


class PashubToAraTriggerRequest(BaseModel):
    pashub_link: str  # e.g. https://pashub.net/jobs/{id}/details, /jobs/{id}/evidence/view, /jobs/{id}

    address: Optional[str] = None
    sharepoint_link: Optional[str] = None
    uprn: Optional[str] = None
    landlord_property_id: Optional[str] = None
    deal_stage: Optional[str] = None
    hubspot_listing_id: Optional[int] = None
    hubspot_deal_id: Optional[str] = None

    @property
    def pashub_job_id(self) -> str:
        match = re.search(r"/jobs/([^/]+)", self.pashub_link)
        if not match:
            raise ValueError(f"No job ID found in PasHub link: {self.pashub_link}")
        return match.group(1)
