# TritonBuilder

***

## TritonBuilder

### Overview

The `TritonBuilder` class is a builder pattern implementation for creating and configuring Pharos log records in Salesforce. It provides a fluent interface to set various attributes like category, type, area, related objects, and other metadata for logging purposes. This class wraps the core `pharos.LogBuilder` to offer a more user-friendly API for log creation.

### Constructor

#### TritonBuilder()

* **Description**: Initializes a new instance of the `TritonBuilder` class, setting default attributes such as the created timestamp and request ID.
* **Usage**:

  ```apex
  TritonBuilder builder = new TritonBuilder();
  ```

### Methods

#### category(TritonTypes.Category c)

* **Description**: Sets the log category from the `Category` enum.
* **Parameters**:
  * `c`: `TritonTypes.Category` [enum value](#category-tritontypes.category-c).
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.category(TritonTypes.Category.Apex);
  ```

#### type(TritonTypes.Type t)

* **Description**: Sets the log type from the [`Type` enum.](#type-tritontypes.type-t)
* **Parameters**:
  * `t`: `TritonTypes.Type` enum value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.type(TritonTypes.Type.Backend);
  ```

#### type(String t)

* **Description**: Sets the log type to a string value, useful when creating a log from an exception.
* **Parameters**:
  * `t`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.type('CustomType');
  ```

#### area(TritonTypes.Area a)

* **Description**: Sets the log functional area from the `Area` enum.
* **Parameters**:
  * `a`: `TritonTypes.Area` enum value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.area(TritonTypes.Area.Community);
  ```

#### area(String a)

* **Description**: Sets the log functional area to a string value, useful from flows.
* **Parameters**:
  * `a`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.area('CustomArea');
  ```

#### level(TritonTypes.Level l)

* **Description**: Sets the log level from the `Level` enum.
* **Parameters**:
  * `l`: `TritonTypes.Level` [enum value](#level-tritontypes.level-l).
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.level(TritonTypes.Level.INFO);
  ```

#### operation(String operation)

* **Description**: Sets the operation from a string value.
* **Parameters**:
  * `operation`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.operation('SampleOperation');
  ```

#### summary(String value)

* **Description**: Sets the log summary from a string value.
* **Parameters**:
  * `value`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.summary('Log Summary');
  ```

#### details(String value)

* **Description**: Sets the log details from a string value.
* **Parameters**:
  * `value`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.details('Detailed log information');
  ```

#### stackTrace(String stack)

* **Description**: Sets the stack trace from a string value.
* **Parameters**:
  * `stack`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.stackTrace('Stack trace details');
  ```

#### postProcessing(TritonHelper.PostProcessingControlsBuilder postProcessingBuilder)

* **Description**: Sets post-processing metadata from a `PostProcessingControlsBuilder` instance.
* **Parameters**:
  * `postProcessingBuilder`: Instance of `TritonHelper.PostProcessingControlsBuilder`.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.postProcessing(new TritonHelper.makeProcessingControlsBuilder()
                                  .userInfo(true));
  ```

#### transactionId(String transactionId)

* **Description**: Sets the transaction ID from a string.
* **Parameters**:
  * `transactionId`: String value.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.transactionId('12345-transaction-id');
  ```

#### createIssue()

* **Description**: Marks the log to create an issue or associate with an existing one.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.createIssue();
  ```

#### userId(Id userId)

* **Description**: Sets the user ID for the log.
* **Parameters**:
  * `userId`: ID of the user to associate with the log.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.userId(UserInfo.getUserId());
  ```

#### relatedObject(Id objectId)

* **Description**: Adds a single related object ID to the log.
* **Parameters**:
  * `objectId`: ID of the object to relate to the log.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.relatedObject(myAccount.Id);
  ```

#### relatedObject(String objectId)

* **Description**: Adds a single related object ID string to the log.
* **Parameters**:
  * `objectId`: String representation of the ID to relate to the log.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.relatedObject('001xx000003DGb2AAG');
  ```

#### relatedObjects(List relatedObjectIds)

* **Description**: Adds multiple related object IDs to the log.
* **Parameters**:
  * `relatedObjectIds`: List of IDs to relate to the log.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.relatedObjects(new List<Id>{'001xx000003DGb2AAG', '001xx000003DGb3AAG'});
  ```

#### relatedObjects(Set relatedObjectIds)

* **Description**: Adds multiple related object ID strings to the log.
* **Parameters**:
  * `relatedObjectIds`: Set of ID strings to relate to the log.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.relatedObjects(new Set<String>{'001xx000003DGb2AAG', '001xx000003DGb3AAG'});
  ```

#### createdTimestamp(Double timestamp)

* **Description**: Sets the created timestamp for the log.
* **Parameters**:
  * `timestamp`: Double value representing the creation timestamp.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.createdTimestamp(Double.valueOf(System.now().getTime()));
  ```

#### duration(Decimal duration)

* **Description**: Sets the duration for the log.
* **Parameters**:
  * `duration`: Decimal value representing the duration.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.duration(123.45);
  ```

#### integrationPayload(HttpRequest request, HttpResponse response)

* **Description**: Sets the integration payload from HTTP request/response.
* **Parameters**:
  * `request`: `HttpRequest` instance.
  * `response`: `HttpResponse` instance.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.integrationPayload(request, response);
  ```

#### integrationPayload(RestRequest request, RestResponse response)

* **Description**: Sets the integration payload from REST request/response.
* **Parameters**:
  * `request`: `RestRequest` instance.
  * `response`: `RestResponse` instance.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.integrationPayload(restRequest, restResponse);
  ```

#### interviewGuid(String guid)

* **Description**: Sets the interview GUID for the log.
* **Parameters**:
  * `guid`: String value of the interview GUID.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.interviewGuid('interview-guid');
  ```

#### flowApiName(String apiName)

* **Description**: Sets the flow API name for the log.
* **Parameters**:
  * `apiName`: String value of the flow API name.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.flowApiName('flow-api-name');
  ```

#### attribute(String name, Object value)

* **Description**: Sets a custom attribute on the log.
* **Parameters**:
  * `name`: String name of the attribute.
  * `value`: Object value of the attribute.
* **Returns**: `TritonBuilder` instance.
* **Usage**:

  ```apex
  builder.attribute('CustomAttribute', 'CustomValue');
  ```

#### build()

* **Description**: Builds and returns the log record.
* **Returns**: `pharos__Log__c` instance.
* **Usage**:

  ```apex
  pharos__Log__c logRecord = builder.build();
  ```
