// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Teams.Core;
using Microsoft.Teams.Core.Hosting;
using Microsoft.Teams.Core.Schema;


string ConversationId = "a:17vxw6pGQOb3Zfh8acXT8m_PqHycYpaFgzu2mFMUfkT-h0UskMctq5ZPPc7FIQxn2bx7rBSm5yE_HeUXsCcKZBrv77RgorB3_1_pAdvMhi39ClxQgawzyQ9GBFkdiwOxT";
string FromId = "28:56653e9d-2158-46ee-90d7-675c39642038";
string ServiceUrl = "https://smba.trafficmanager.net/teams/";

ConversationClient conversationClient = CreateConversationClient();

CoreActivity msgOne = CoreActivity.CreateBuilder()
    .WithType(ActivityType.Message)
    .WithServiceUrl(new Uri(ServiceUrl))
    .WithConversation(new(ConversationId))
    .WithFrom(new ConversationAccount { Id = FromId })
    .WithProperty("text", "Test Message")
    .Build();

await conversationClient.SendActivityAsync(msgOne, cancellationToken: default);

await conversationClient.SendActivityAsync(CoreActivity.CreateBuilder()
    .WithConversation(new Conversation("bad conversation"))
    .WithServiceUrl(new Uri(ServiceUrl))
    .WithFrom(new ConversationAccount {  Id = FromId})
    .Build(), cancellationToken: default);



static ConversationClient CreateConversationClient()
{
    ServiceCollection services = InitializeDIContainer();
    services.AddConversationClient();
    ServiceProvider serviceProvider = services.BuildServiceProvider();
    ConversationClient conversationClient = serviceProvider.GetRequiredService<ConversationClient>();
    return conversationClient;
}

static ServiceCollection InitializeDIContainer()
{
    IConfigurationBuilder builder = new ConfigurationBuilder()
                    .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                    .AddEnvironmentVariables();

    IConfiguration configuration = builder.Build();

    ServiceCollection services = new();
    services.AddSingleton(configuration);
    services.AddLogging(configure => configure.AddConsole());
    return services;
}
