[docs]classWatchlist(BaseModel):"""Used to represent a watchlist"""model_config=ConfigDict(populate_by_name=True,alias_generator=to_camel)id:str=Field(validation_alias="key")name:strdate_created:Optional[datetime]=None# Not returned by autosuggestlast_updated:Optional[datetime]=None# Not returned by autosuggestquery_type:Literal["watchlist"]=Field(default="watchlist",validation_alias="queryType")company_shared_permission:SharePermission=SharePermission.UNDEFINED_items_initialized:bool=PrivateAttr(default=False)_items=PrivateAttr(default=[])# Keeps track of the connection to Bigdata_api:BigdataConnectionProtocol
@propertydefitems(self)->list[str]:ifnotself._items_initialized:self._items=self._api.get_single_watchlist(self.id).itemsor[]self._items_initialized=Truereturnself._items@items.setterdefitems(self,value:list[str]):self._items=valueself._items_initialized=Truedef__eq__(self,other):# To avoid problems when comparing 2 objects with different privateAttrreturnself.model_dump()==other.model_dump()# Watchlist operations
[docs]defsave(self):"""Save a watchlist"""self._api.patch_watchlist(self.id,UpdateWatchlistRequest(name=self.name,items=self.items))
[docs]defshare_with_company(self):"""Share this watchlist with every member of the company"""self._api.share_unshare_watchlist(self.id,ShareUnshareWatchlistRequest(company=ShareWatchlistCompany(permission=SharePermission.READ)),)self.company_shared_permission=SharePermission.READ
[docs]defunshare_with_company(self):"""Stop sharing this watchlist with every member of the company"""self._api.share_unshare_watchlist(self.id,ShareUnshareWatchlistRequest(company=ShareWatchlistCompany(permission=SharePermission.UNDEFINED)),)self.company_shared_permission=SharePermission.UNDEFINED
[docs]defdelete(self):"""Delete the watchlist"""returnself._api.delete_watchlist(self.id).id