package com.ruoyi.xq.manager;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.xq.domain.Dynamic;
import com.ruoyi.xq.domain.UserAuthAudit;
import com.ruoyi.xq.domain.UserInfoAudit;
import com.ruoyi.xq.domain.UserWithdraw;
import com.ruoyi.xq.dto.admin.unread.UnreadData;
import com.ruoyi.xq.enums.common.AuditEnum;
import com.ruoyi.xq.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UnreadManager {

    @Autowired
    private UserWithdrawService userWithdrawService;
    @Autowired
    private UserAuthAuditService userAuthAuditService;
    @Autowired
    private DynamicService dynamicService;
    @Autowired
    private UserInfoAuditService userInfoAuditService;


    public UnreadData data() {
        UnreadData unreadData = new UnreadData();
        long userWithdraw = userWithdrawService.count(Wrappers.lambdaQuery(UserWithdraw.class).eq(UserWithdraw::getAuditStatus, AuditEnum.AUDITING.getCode()));
        unreadData.setUserWithdrawCount(userWithdraw);

        long userAuth = userAuthAuditService.count(Wrappers.lambdaQuery(UserAuthAudit.class).eq(UserAuthAudit::getAuditStatus, AuditEnum.AUDITING.getCode()));
        unreadData.setUserAuthCount(userAuth);

        long dynamic = dynamicService.count(Wrappers.lambdaQuery(Dynamic.class).eq(Dynamic::getAuditStatus, AuditEnum.AUDITING.getCode()));
        unreadData.setDynamicCount(dynamic);

        long userInfo = userInfoAuditService.count(Wrappers.lambdaQuery(UserInfoAudit.class).eq(UserInfoAudit::getAuditStatus, AuditEnum.AUDITING.getCode()));
        unreadData.setUserInfoCount(userInfo);
        return unreadData;
    }

    public boolean checkCount() {
        boolean userWithdraw = userWithdrawService.exists(Wrappers.lambdaQuery(UserWithdraw.class).eq(UserWithdraw::getAuditStatus, AuditEnum.AUDITING.getCode()));
        if(userWithdraw){
            return true;
        }

        boolean userAuth = userAuthAuditService.exists(Wrappers.lambdaQuery(UserAuthAudit.class).eq(UserAuthAudit::getAuditStatus, AuditEnum.AUDITING.getCode()));
        if(userAuth){
            return true;
        }

        boolean dynamic = dynamicService.exists(Wrappers.lambdaQuery(Dynamic.class).eq(Dynamic::getAuditStatus, AuditEnum.AUDITING.getCode()));
        if(dynamic){
            return true;
        }

        boolean userInfo = userInfoAuditService.exists(Wrappers.lambdaQuery(UserInfoAudit.class).eq(UserInfoAudit::getAuditStatus, AuditEnum.AUDITING.getCode()));
        if(userInfo){
            return true;
        }
        return false;

    }
}
