using System;
using System.IO;
using Newtonsoft.Json;

namespace IntegrationTests;

public static class HelperMethods {
    public static (string id, string secret) GetSecrets() {
        // relative to the project execution directory
        const string secretFile = "../../../http-client.env.json";

        if (!File.Exists(secretFile)) {
            // If the secret file is not found, create it with the default values
            // The file will be pretty in C#11, when """ is introduced
            File.WriteAllText(secretFile, @"
{
    ""sender"": {
        ""id"": ""00000000-0000-0000-0000-000000000000"",
        ""secret"": ""0000000000000000000000000000000000000000000"",
        ""scope"": ""send:region:DE""
    }
}");
            throw new Exception("Please fill the secret.json file with your sender credentials");
        }

        var jsonContent = File.ReadAllText(secretFile);
        var secret = JsonConvert.DeserializeObject<dynamic>(jsonContent);
        return (secret!.sender.id, secret.sender.secret);
    }
}