~ruther/NosSmooth

ref: 72b5ea6b07d233eacb75a05344f06b50c3093166 NosSmooth/Core/NosSmooth.Core/Contracts/ContractBuilder.cs -rw-r--r-- 2.4 KiB
72b5ea6b — František Boháček feat(core): add contract builder outline 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
//  ContractBuilder.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Remora.Results;

namespace NosSmooth.Core.Contracts;

/// <summary>
/// Builds <see cref="IContract"/> with given states
/// and errors.
/// </summary>
/// <typeparam name="TData">The data type.</typeparam>
/// <typeparam name="TState">The states.</typeparam>
/// <typeparam name="TError">The errors that may be returned.</typeparam>
public class ContractBuilder<TData, TState, TError>
    where TState : struct, IComparable
    where TError : struct
    where TData : notnull
{
    private readonly Contractor _contractor;
    private readonly TState _defaultState;

    private TState? _fillAtState;
    private DefaultContract<TData, TState, TError>.FillDataAsync? _fillData;
    private Dictionary<TState, DefaultContract<TData, TState, TError>.StateActionAsync> _actions;

    /// <summary>
    /// Initializes a new instance of the <see cref="ContractBuilder{TData, TState, TError}"/> class.
    /// </summary>
    /// <param name="contractor">The contractor.</param>
    /// <param name="defaultState">The default state of the contract.</param>
    public ContractBuilder(Contractor contractor, TState defaultState)
    {
        _contractor = contractor;
        _defaultState = defaultState;
        _actions = new Dictionary<TState, DefaultContract<TData, TState, TError>.StateActionAsync>();
    }

    public ContractBuilder SetMoveFilter<TAny>(TState state, Func<TAny, bool> filter, TState nextState)
    {

    }
    
    public ContractBuilder SetMoveFilter<TAny>(TState state, TState nextState)
    {

    }

    public ContractBuilder SetFillData<TAny>(TState state, Func<TAny, Result<TData>> fillData)
    {
        _fillAtState = state;
        _fillData = fillData;
    }
    
    public ContractBuilder SetError<TAny>(TState state, Func<TAny, TError?> error, TState nextState)
    {

    }

    public ContractBuilder SetMoveAction<TAny>(TState state, Func<TAny, Task<Result<bool>>> actionFilter, TState nextState)
    {

    }

    public ContractBuilder SetPacketError<TAny>(TState state, Func<TAny, TError?> error, TState nextState)
    {

    }

    public IContract Build()
    {
        new DefaultContract<TData, TState, TError>()
    }
}
Do not follow this link