using Microsoft.Extensions.Options;

namespace Lactose.Configuration;

public class SignKeyProvider(IConfiguration configuration) : IConfigureOptions<SignKeyConfiguration> {
    
    const string SectionName = SignKeyConfiguration.SectionName+":Key";
    public void Configure(SignKeyConfiguration options) {
        
        if (configuration[SectionName]!.Length <= 32 ) {
            throw new Exception("SignKey:Key is not 256 bits long");
        }
        options.Key = configuration[SectionName] ?? throw new Exception("SignKey:Key is not set");
    }

    public SignKeyConfiguration Get() {
        var options = new SignKeyConfiguration();
        this.Configure(options);
        return options; 
    }
}
