package basic import ( "context" "git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model" "strconv" ) // PoolBuilder represents a builder for constructing queries to retrieve a specific pool. type PoolBuilder interface { // ID sets the pool ID for the query. ID(poolID int) PoolBuilder // Execute sends the constructed query and returns the requested pool and an error, if any. Execute() (model.Pool, error) } // NewGetPoolBuilder creates a new instance of PoolBuilder with the provided RequestContext. // // Parameters: // - requestContext: The context for the API request, including the host, user agent, username, and API key. // // Returns: // - PoolBuilder: An instance of the PoolBuilder interface. func NewGetPoolBuilder(requestContext model.RequestContext) PoolBuilder { return &getPool{requestContext: requestContext} } // getPool is an implementation of the PoolBuilder interface. type getPool struct { requestContext model.RequestContext id int } // ID sets the pool ID for the query. // // Parameters: // - poolID: The ID of the pool to be retrieved. // // Returns: // - PoolBuilder: The instance of the PoolBuilder for method chaining. func (g *getPool) ID(poolID int) PoolBuilder { g.id = poolID return g } // Execute sends the constructed query and returns the requested pool and an error, if any. // // Returns: // - model.Pool: The requested pool. // - error: An error, if any, encountered during the API request or response handling. func (g *getPool) Execute() (model.Pool, error) { if g.requestContext.RateLimiter != nil { err := g.requestContext.RateLimiter.Wait(context.Background()) if err != nil { return model.Pool{}, err } } pool, err := endpoints.GetPool(g.requestContext, strconv.Itoa(g.id)) if err != nil { return model.Pool{}, err } return pool, nil }