using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Tiku.Application.Assets;
using Tiku.Application.Learning;
using Tiku.Application.PlatformAdmin;
using Tiku.Application.Security;
using Tiku.Domain.Common;
using Tiku.Domain.Content;
using Tiku.Domain.Operations;
using Tiku.Domain.QuestionBanks;
using Tiku.Domain.Tenancy;
using Tiku.Infrastructure.Persistence;

namespace Tiku.Infrastructure.PlatformAdmin;

internal abstract partial class PlatformQuestionBankServiceBase
{
    protected Task<AssetUploadSignResult> SignQuestionAssetUploadCoreAsync(PlatformAdminActor actor,
        AssetUploadSignCommand command, CancellationToken cancellationToken = default)
    {
        return ExecuteAsync(actor, "签发公共题库图片上传地址", async (provider, _, tenantId, token) =>
                await provider.GetRequiredService<IAssetUploadManagementService>().SignUploadAsync(
                    new AssetManagementActor(tenantId, actor.UserId),
                    command with { AssetType = "image", Category = "question", IsPublic = true }, token),
            cancellationToken);
    }

    protected Task<AssetUploadConfirmResult> ConfirmQuestionAssetUploadCoreAsync(PlatformAdminActor actor,
        AssetUploadConfirmCommand command, CancellationToken cancellationToken = default)
    {
        return ExecuteAsync(actor, "确认公共题库图片上传", async (provider, _, tenantId, token) =>
                await provider.GetRequiredService<IAssetUploadManagementService>()
                    .ConfirmUploadAsync(new AssetManagementActor(tenantId, actor.UserId), command, token),
            cancellationToken);
    }

}
