public async Task <Result <Unit, Contracts.Error> > SetAsync(string gallery, Contracts.ProcessingConfiguration configuration)
        {
            var result = await Name.FromString(gallery)
                         .AndThenAsync(name => FromContract(configuration)
                                       .AndThenAsync(config => _storage.Persist(name, config)));

            return(result.MapFailure(ErrorExtensions.ToContract));
        }
        private static Result <Configuration.ProcessingConfiguration, Error> FromContract(Contracts.ProcessingConfiguration value)
        {
            var sizesResult = value.Sizes.Select(s =>
            {
                var cropResult = Result.Success <Option <Configuration.CropConfiguration>, Error>(Option.None());
                if (s.Crop != null)
                {
                    if (Enum.TryParse <CropStrategy>(s.Crop.CropStrategy, true, out var strategy))
                    {
                        var colorResult = Result.Success <Option <Color>, Error>(Option.None());
                        if (s.Crop.Color != null)
                        {
                            colorResult = Color.FromString(s.Crop.Color).MapSuccess(c => Option.Some(c));
                        }

                        cropResult = colorResult.AndThen(color => AspectRatio.FromString(s.Crop.AspectRatio)
                                                         .MapSuccess(ratio => Option.Some(new Configuration.CropConfiguration(ratio, strategy, color))));
                    }
                    else
                    {
                        cropResult = Result.Failure(Error.ValidationError($"Unknown crop strategy {s.Crop.CropStrategy}"));
                    }
                }

                return(cropResult
                       .AndThen(crop => Name.FromString(s.Tag)
                                .AndThen(tag => Quality.FromScalar(s.Quality)
                                         .AndThen(quality => ImageFormat.FromExtension(s.Format)
                                                  .MapSuccess(format => new Configuration.SizeConfiguration(
                                                                  tag,
                                                                  s.MaxWidth.ToOption(),
                                                                  s.MaxHeight.ToOption(),
                                                                  crop,
                                                                  quality,
                                                                  format))))));
            }).Railway();

            return(sizesResult.AndThen(sizes => Configuration.ProcessingConfiguration.New(
                                           value.AvoidDuplicates,
                                           sizes
                                           )));
        }