using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Enums.KnowledgeBase;
using Hotline.Share.Enums.ThirdAccount;
using Hotline.Share.Enums.User;
using Hotline.ThirdAccountDomainServices.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Dependency;

namespace Hotline.ThirdAccountDomainServices;
public class ThirdAccounSupplierFactory : IThirdAccountSupplier, ISelfDependency, IScopeDependency
{
    private readonly IEnumerable<IThirdAccountSupplier> _serviceItems;

    public ThirdAccounSupplierFactory(IEnumerable<IThirdAccountSupplier> serviceItems)
    {
        _serviceItems = serviceItems;
    }

    public IThirdAccountSupplier GetSupplier(EAppType enumType)
        => _serviceItems
        .FirstOrDefault(supplier => supplier.GetType().Name.ToLower().StartsWith(enumType.ToString().ToLower()))
        ?? _serviceItems.First();

    public async Task<string> GetClaimAsync(ThirdAccount account, List<Claim> claims, CancellationToken token)
        => await GetSupplier(account.AppType).GetClaimAsync(account, claims, token);

    public async Task<Dictionary<string, object>> GetLoginOutDataAsync(ThirdAccount thirdAccount, Dictionary<string, object> dicOutData, CancellationToken cancel)
        => await GetSupplier(thirdAccount.AppType).GetLoginOutDataAsync(thirdAccount, dicOutData, cancel);

    public async Task<ThirdTokenDto> GetThirdParameterAsync(ThirdTokenDto thirdDto, CancellationToken token)
        => await GetSupplier(thirdDto.AppType).GetThirdParameterAsync(thirdDto, token);

    public async Task RegisterAsync(ThirdAccount account, CancellationToken token)
        => await GetSupplier(account.AppType).RegisterAsync(account, token);
}

