private Result <Security.SecurityConfiguration, Error> ToConfiguration(Contracts.SecurityConfiguration model)
        {
            var accountsResult = model.Accounts.Select(a =>
            {
                if (!Enum.TryParse <AccountType>(a.Type, true, out var type))
                {
                    return(Result.Failure <Security.AccountConfiguration, Error>(Error.ValidationError($"Unknown account type {a.Type}")));
                }

                var permissionResults = a.Permissions.Select(Permission.FromString).ToArray();
                if (permissionResults.Any(r => r.IsFailure))
                {
                    return(Result.Failure(permissionResults.SelectFailure().First()));
                }

                return(Name.FromString(a.Name).AndThen(name => Security.AccountConfiguration.New(
                                                           name,
                                                           type,
                                                           a.Password?.Length > 0 ? Option.Some(a.Password) : Option.None(),
                                                           permissionResults.SelectSuccess().ToValueObjectSet())));
            }).Railway();

            return(accountsResult.AndThen(accounts => Security.SecurityConfiguration.New(accounts)));
        }
        public async Task <Result <Unit, Contracts.Error> > SetGlobalAsync(Contracts.SecurityConfiguration configuration)
        {
            var result = await ToConfiguration(configuration).AndThenAsync(config => _storage.PersistGlobal(config));

            return(result.MapFailure(ErrorExtensions.ToContract));
        }
        public async Task <Result <Unit, Contracts.Error> > SetAsync(string galleryName, Contracts.SecurityConfiguration configuration)
        {
            var result = await Name.FromString(galleryName)
                         .AndThenAsync(gallery => ToConfiguration(configuration)
                                       .AndThenAsync(config => _storage.Persist(gallery, config)));

            return(result.MapFailure(ErrorExtensions.ToContract));
        }