package com.red.circle.console.app.service.admin;

import com.red.circle.console.app.command.admin.AccountInfoUpdateCmdExe;
import com.red.circle.console.app.command.admin.AccountPasswordUpdateCmdExe;
import com.red.circle.console.app.command.admin.ConsoleLoginCmdExe;
import com.red.circle.console.app.command.admin.UserAddCmdExe;
import com.red.circle.console.app.command.admin.UserResetPwdCmdExe;
import com.red.circle.console.app.command.admin.UserUpdateCmdExe;
import com.red.circle.console.app.command.admin.query.AccountButtonsAliasesQryExe;
import com.red.circle.console.app.command.admin.query.AccountMenuQryExe;
import com.red.circle.console.app.command.admin.query.UserAllComboQryExe;
import com.red.circle.console.app.command.admin.query.UserDetailsQryExe;
import com.red.circle.console.app.command.admin.query.UserPageQryExe;
import com.red.circle.console.app.command.admin.query.UserSingleQryExe;
import com.red.circle.console.app.dto.clienobject.admin.ComboUserCO;
import com.red.circle.console.app.dto.clienobject.admin.ConsoleTokenCO;
import com.red.circle.console.app.dto.clienobject.admin.MenuTreeCO;
import com.red.circle.console.app.dto.clienobject.admin.UserCO;
import com.red.circle.console.app.dto.clienobject.admin.UserDetailsCO;
import com.red.circle.console.app.dto.cmd.admin.AccountInfoCmd;
import com.red.circle.console.app.dto.cmd.admin.PasswordCmd;
import com.red.circle.console.app.dto.cmd.admin.UserCmd;
import com.red.circle.console.app.dto.cmd.admin.UserIdCmd;
import com.red.circle.console.app.dto.cmd.admin.UserPageQryCmd;
import com.red.circle.console.inner.model.cmd.LoginCmd;
import com.red.circle.framework.core.dto.CommonCommand;
import com.red.circle.framework.dto.PageResult;

import java.util.List;
import java.util.Set;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import static com.red.circle.tool.core.text.StringPool.SYMBOL_COMMA;

/**
 * 管理后台，账号服务 实现.
 *
 * @author pengliang on 2023/5/11
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserAccountServiceImpl implements UserAccountService {

    private final UserAddCmdExe userAddCmdExe;
    private final UserPageQryExe userPageQryExe;
    private final UserUpdateCmdExe userUpdateCmdExe;
    private final UserSingleQryExe userSingleQryExe;
    private final AccountMenuQryExe accountMenuQryExe;
    private final UserDetailsQryExe userDetailsQryExe;
    private final UserAllComboQryExe userAllComboQryExe;
    private final UserResetPwdCmdExe userResetPwdCmdExe;
    private final ConsoleLoginCmdExe consoleLoginCmdExe;
    private final AccountInfoUpdateCmdExe accountInfoUpdateCmdExe;
    private final AccountButtonsAliasesQryExe accountButtonsAliasesQryExe;
    private final AccountPasswordUpdateCmdExe accountPasswordUpdateCmdExe;

    @Override
    public ConsoleTokenCO login(LoginCmd cmd) {
        return consoleLoginCmdExe.execute(cmd);
    }

    @Override
    public UserDetailsCO getUserDetails(CommonCommand cmd) {
        return userDetailsQryExe.execute(cmd);
    }

    @Override
    public void updatePassword(PasswordCmd cmd) {
        accountPasswordUpdateCmdExe.execute(cmd);
    }

    @Override
    public void updateAccountInfo(AccountInfoCmd cmd) {
        accountInfoUpdateCmdExe.execute(cmd);
    }

    @Override
    public List<MenuTreeCO> listAccountMenus(CommonCommand cmd) {
        return accountMenuQryExe.execute(cmd);
    }

    @Override
    public Set<String> listAccountButtonsAliases(CommonCommand cmd) {
        return accountButtonsAliasesQryExe.execute(cmd);
    }

    @Override
    public boolean hasButtonsAlias(Integer userId, String alias) {
      return accountButtonsAliasesQryExe.hasButtonAlias(userId, alias);
    }

  @Override
    public PageResult<UserCO> pageUser(UserPageQryCmd cmd) {
        return userPageQryExe.execute(cmd);
    }

    @Override
    public UserCO getUser(UserIdCmd cmd) {
        return userSingleQryExe.execute(cmd);
    }

    @Override
    public void resetPassword(UserIdCmd cmd) {
        userResetPwdCmdExe.execute(cmd);
    }

    @Override
    public void addUser(UserCmd cmd) {
        userAddCmdExe.execute(cmd);
    }

    @Override
    public void updateUser(UserCmd cmd) {
        userUpdateCmdExe.execute(cmd);
    }

    @Override
    public List<ComboUserCO> listUser() {
        return userAllComboQryExe.execute();
    }
}
