package cn.reghao.tnb.auth.app.rpc;

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.auth.api.dto.AccountInfo;
import cn.reghao.tnb.auth.api.dto.AccountRegistry;
import cn.reghao.tnb.auth.api.dto.AccountRegistryStatus;
import cn.reghao.tnb.auth.api.iface.AdminAccountService;
import cn.reghao.tnb.auth.app.db.repository.AccountRepository;
import cn.reghao.tnb.auth.app.model.po.UserRegistry;
import cn.reghao.tnb.auth.app.service.AccountRegistryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

/**
 * @author reghao
 * @date 2024-07-31 07:00:22
 */
@Slf4j
@DubboService
@Service
public class AdminAccountServiceImpl implements AdminAccountService {
    private final AccountRepository accountRepository;
    private final AccountRegistryService accountRegistryService;

    public AdminAccountServiceImpl(AccountRepository accountRepository, AccountRegistryService accountRegistryService) {
        this.accountRepository = accountRepository;
        this.accountRegistryService = accountRegistryService;
    }

    @Override
    public AccountRegistry getAccountRegistry() {
        UserRegistry userRegistry = accountRepository.getUserRegistry();
        return new AccountRegistry(userRegistry.getEnabled(), userRegistry.getCaptchaCode(), userRegistry.getVerifyCode(), userRegistry.getEnableVerify());
    }

    @Override
    public void setAccountRegistry(AccountRegistryStatus accountRegistryStatus) {
        UserRegistry userRegistry = accountRepository.getUserRegistry();
        userRegistry.setEnabled(accountRegistryStatus.getEnabled());
        accountRepository.updateUserRegistry(userRegistry);
    }

    @Override
    public void setAccountCode(AccountRegistryStatus accountRegistryStatus) {
        UserRegistry userRegistry = accountRepository.getUserRegistry();
        userRegistry.setEnableCaptcha(accountRegistryStatus.getEnabled());
        accountRepository.updateUserRegistry(userRegistry);
    }

    public PageList<AccountInfo> getByScreenName(String screenName, int pageNumber, int pageSize) {
        return PageList.empty();
    }
}
