1212if TYPE_CHECKING :
1313 from stapi_fastapi .backends .product_backend import (
1414 CreateOrder ,
15+ GetOpportunityCollection ,
1516 SearchOpportunities ,
17+ SearchOpportunitiesAsync ,
1618 )
1719
1820
@@ -54,33 +56,42 @@ class Product(BaseModel):
5456 _opportunity_properties : type [OpportunityProperties ]
5557 _order_parameters : type [OrderParameters ]
5658 _create_order : CreateOrder
57- _search_opportunities : SearchOpportunities
5859
5960 def __init__ (
6061 self ,
6162 * args ,
62- create_order : CreateOrder ,
63- search_opportunities : SearchOpportunities ,
6463 constraints : type [Constraints ],
6564 opportunity_properties : type [OpportunityProperties ],
6665 order_parameters : type [OrderParameters ],
66+ create_order : CreateOrder ,
67+ search_opportunities : SearchOpportunities | None = None ,
68+ search_opportunities_async : SearchOpportunitiesAsync | None = None ,
69+ get_opportunity_collection : GetOpportunityCollection | None = None ,
6770 ** kwargs ,
6871 ) -> None :
6972 super ().__init__ (* args , ** kwargs )
70- self ._create_order = create_order
71- self ._search_opportunities = search_opportunities
73+
74+ if bool (search_opportunities_async ) != bool (get_opportunity_collection ):
75+ raise ValueError (
76+ "Both the `search_opportunities_async` and `get_opportunity_collection` "
77+ "arguments must be provided if either is provided"
78+ )
79+
7280 self ._constraints = constraints
7381 self ._opportunity_properties = opportunity_properties
7482 self ._order_parameters = order_parameters
83+ self ._create_order = create_order
84+ if search_opportunities is not None :
85+ self ._search_opportunities = search_opportunities
86+ if search_opportunities_async is not None :
87+ self ._search_opportunities_async = search_opportunities_async
88+ if get_opportunity_collection is not None :
89+ self ._get_opportunity_collection = get_opportunity_collection
7590
7691 @property
7792 def create_order (self : Self ) -> CreateOrder :
7893 return self ._create_order
7994
80- @property
81- def search_opportunities (self : Self ) -> SearchOpportunities :
82- return self ._search_opportunities
83-
8495 @property
8596 def constraints (self : Self ) -> type [Constraints ]:
8697 return self ._constraints
@@ -93,6 +104,16 @@ def opportunity_properties(self: Self) -> type[OpportunityProperties]:
93104 def order_parameters (self : Self ) -> type [OrderParameters ]:
94105 return self ._order_parameters
95106
107+ @property
108+ def supports_opportunity_search (self : Self ) -> bool :
109+ return hasattr (self , "_search_opportunities" )
110+
111+ @property
112+ def supports_async_opportunity_search (self : Self ) -> bool :
113+ return hasattr (self , "_search_opportunities_async" ) and hasattr (
114+ self , "_get_opportunity_collection"
115+ )
116+
96117 def with_links (self : Self , links : list [Link ] | None = None ) -> Self :
97118 if not links :
98119 return self
0 commit comments