| | | 1 | | using Enjoy.Domain.Shared.Errors; |
| | | 2 | | using Enjoy.Domain.Shared.Extensions; |
| | | 3 | | using Enjoy.Domain.Shared.Results; |
| | | 4 | | |
| | | 5 | | namespace Enjoy.Domain.Jokes.ValueObjects; |
| | | 6 | | |
| | | 7 | | public readonly record struct JokeText |
| | | 8 | | { |
| | 12 | 9 | | public string Value { get; } |
| | | 10 | | |
| | | 11 | | public const int MaxLength = 2000; |
| | | 12 | | |
| | 37 | 13 | | private JokeText(string value) => Value = value; |
| | | 14 | | |
| | | 15 | | public static Result<JokeText> Create(string? value) |
| | 45 | 16 | | { |
| | 45 | 17 | | if (string.IsNullOrWhiteSpace(value)) |
| | 7 | 18 | | return Result<JokeText>.Failure(Error.JokeText.IsNullOrEmpty); |
| | | 19 | | |
| | 38 | 20 | | var normalized = value.NormalizeWhitespace(); |
| | 38 | 21 | | if (normalized.Length > MaxLength) |
| | 1 | 22 | | return Result<JokeText>.Failure(Error.JokeText.TooLong(MaxLength)); |
| | | 23 | | |
| | 37 | 24 | | return Result<JokeText>.Success(new JokeText(normalized)); |
| | 45 | 25 | | } |
| | | 26 | | |
| | 1 | 27 | | public override string ToString() => Value; |
| | | 28 | | |
| | 1 | 29 | | public static implicit operator string(JokeText text) => text.Value; |
| | | 30 | | } |