using Hotline.Api.Controllers;
using Hotline.Caching.Interfaces;
using Hotline.Caching.Services;
using Hotline.Identity.Accounts;
using Hotline.Identity.Roles;
using Hotline.Settings;
using Hotline.ThirdAccountDomainServices;
using Hotline.ThirdAccountDomainServices.Interfaces;
using Hotline.Users;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Cache;
using XF.Domain.Repository;

namespace Hotline.Tests.Application;
public class SystemSettingCacheManagerTest : TestBase
{
    private readonly ISystemSettingCacheManager _systemSettingCacheManager;
    private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
    private readonly IRepository<SystemSetting> _systemSettingRepository;

    public SystemSettingCacheManagerTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, ISystemSettingCacheManager systemSettingCacheManager, ISystemDicDataCacheManager systemDicDataCacheManager, IRepository<SystemSetting> systemSettingRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
    {
        _systemSettingCacheManager = systemSettingCacheManager;
        _systemDicDataCacheManager = systemDicDataCacheManager;
        _systemSettingRepository = systemSettingRepository;
    }

    [Fact]
    public void CancelPublishOrderEnabled_Test()
    {
        var time = _systemSettingCacheManager.SnapshotIntervalMinutes;
        time.ShouldBe(20);
        var dd = DateTime.Parse("11/19/2024 18:08:00");
        _systemSettingCacheManager.CallSyncUnPushDateTime.ShouldBe(DateTime.Parse("2025/04/11 15:40:00"));
        //var result = _systemSettingCacheManager.CancelPublishOrderEnabled;
        //result.ShouldBeTrue();
        var seconds = _systemSettingCacheManager.VisitCallDelaySecond;
        seconds.ShouldBe(60);

        var delaySecond =  _systemSettingCacheManager.DefaultVisitSmsDelaySecond;
        delaySecond.ShouldBe(172800);
        var delaySecondEntity = _systemSettingRepository.GetAsync("08dc0681-a6d2-4ce7-877d-db65f846d523");
        delaySecondEntity.ShouldNotBeNull("DefaultVisitSmsDelaySecond 系统设置为NULL");

        _systemSettingCacheManager.GetAboutToExpireVersion.ShouldBe(0);

        _systemSettingCacheManager.WxOpenAppId.ShouldNotBeNull();
        _systemSettingCacheManager.WxOpenAppSecret.ShouldNotBeNull();
        _systemSettingCacheManager.VisitCallDelaySecond.ShouldNotBe(0);
        _systemSettingCacheManager.AutomaticPublishOrder.ShouldBe(true);
        //_systemSettingCacheManager.CancelPublishOrderEnabled.ShouldBe(true);

        _systemDicDataCacheManager.RemoveSysDicDataCache(SysDicTypeConsts.Workplace);
        var workplace = _systemDicDataCacheManager.Workplace;
        workplace.ShouldNotBeNull();
        workplace.Count.ShouldNotBe(0);

        _systemDicDataCacheManager.RemoveSysDicDataCache(SysDicTypeConsts.WorkplaceName);
        var workArea = _systemDicDataCacheManager.WorkplaceName;
        workArea.ShouldNotBeNull();
        workArea.Count.ShouldNotBe(0);

        _systemDicDataCacheManager.RemoveSysDicDataCache(SysDicTypeConsts.SnapshotBulletinType);
        var snapshotBulletinType = _systemDicDataCacheManager.SnapshotBulletinType;
        snapshotBulletinType.ShouldNotBeNull();
        snapshotBulletinType.Count.ShouldNotBe(0);
    }
}
