Skip to content

Commit

Permalink
refactor: builders for NumberInsightsV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 7, 2024
1 parent 62467b2 commit 991dca1
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Vonage/NumberInsightV2/FraudCheck/FraudCheckRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

namespace Vonage.NumberInsightV2.FraudCheck;

internal class FraudCheckRequestBuilder : IBuilderForPhone, IBuilderForOptional
internal struct FraudCheckRequestBuilder : IBuilderForPhone, IBuilderForOptional
{
private readonly HashSet<string> insights = new();
private Result<PhoneNumber> phone;
private readonly HashSet<string> insights = new HashSet<string>();
private Result<PhoneNumber> phone = default;

public FraudCheckRequestBuilder()
{
}

/// <inheritdoc />
public Result<FraudCheckRequest> Create() =>
Expand All @@ -26,11 +30,7 @@ public IBuilderForOptional WithFraudScore()
}

/// <inheritdoc />
public IBuilderForOptional WithPhone(string value)
{
this.phone = PhoneNumber.Parse(value);
return this;
}
public IBuilderForOptional WithPhone(string value) => this with {phone = PhoneNumber.Parse(value)};

/// <inheritdoc />
public IBuilderForOptional WithSimSwap()
Expand All @@ -42,10 +42,11 @@ public IBuilderForOptional WithSimSwap()
private static IResultFailure ToParsingFailure(IResultFailure failure) =>
ParsingFailure.FromFailures(ResultFailure.FromErrorMessage(failure.GetFailureMessage()));

private FraudCheckRequest ToRequest(PhoneNumber number) => new()
{
Phone = number, Insights = this.insights,
};
private FraudCheckRequest ToRequest(PhoneNumber number) =>
new FraudCheckRequest
{
Phone = number, Insights = this.insights,
};

private static Result<FraudCheckRequest> VerifyInsights(FraudCheckRequest request) =>
InputValidation.VerifyNotEmpty(request, request.Insights, nameof(request.Insights));
Expand Down

0 comments on commit 991dca1

Please sign in to comment.