using Hotline.Settings.TimeLimitDomain.ExpireTimeSupplier;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Enums.Settings;
using Hotline.Share.Enums.User;
using Hotline.ThirdAccountDomainServices.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Dependency;

namespace Hotline.ThirdAccountDomainServices;
public class ThirdIdentiyFactory : IThirdIdentiyService, ISelfDependency, IScopeDependency
{
    private readonly IEnumerable<IThirdIdentiyService> _thirdIdentityServices;

    public ThirdIdentiyFactory(IEnumerable<IThirdIdentiyService> thirdIdentityServices)
    {
        _thirdIdentityServices = thirdIdentityServices;
    }

    public IThirdIdentiyService GetSupplier(EThirdType thirdType)
        => _thirdIdentityServices
        .FirstOrDefault(supplier => supplier.GetType().Name.ToLower().StartsWith(thirdType.ToString().ToLower()))
        ?? _thirdIdentityServices.First();

    public async Task<ThirdTokenOutDto> GetTokenAsync(ThirdTokenDto dto, CancellationToken token)
        => await GetSupplier(dto.ThirdType).GetTokenAsync(dto, token);

    public async Task<ThirdPhoneOutDto> GetPhoneNumberAsync(ThirdTokenDto dto, CancellationToken token)
        => await GetSupplier(dto.ThirdType).GetPhoneNumberAsync(dto, token);
}
