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

import com.alibaba.fastjson.JSON;
import com.red.circle.console.app.command.admin.RoleAddCmdExe;
import com.red.circle.console.app.command.admin.RoleMenuUpdateCmdExe;
import com.red.circle.console.app.command.admin.RoleRemoveCmdExe;
import com.red.circle.console.app.command.admin.RoleUpdateCmdExe;
import com.red.circle.console.app.command.admin.query.RoleAllQryExe;
import com.red.circle.console.app.command.admin.query.RolePageQryExe;
import com.red.circle.console.app.command.admin.query.RoleSingleQryExe;
import com.red.circle.console.app.dto.clienobject.admin.RoleCO;
import com.red.circle.console.app.dto.cmd.admin.PageRoleQryCmd;
import com.red.circle.console.app.dto.cmd.admin.RoleCmd;
import com.red.circle.console.app.dto.cmd.admin.RoleIdCmd;
import com.red.circle.console.app.dto.cmd.admin.RoleMenuUpdateCmd;
import com.red.circle.framework.dto.PageResult;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 角色服务 实现.
 *
 * @author pengliang on 2023/5/12
 */
@Service
@RequiredArgsConstructor
public class AdminRoleServiceImpl implements AdminRoleService {

  private final RoleAllQryExe roleAllQryExe;
  private final RolePageQryExe rolePageQryExe;
  private final RoleAddCmdExe roleAddCmdExe;
  private final RoleSingleQryExe roleSingleQryExe;
  private final RoleUpdateCmdExe roleUpdateCmdExe;
  private final RoleRemoveCmdExe roleRemoveCmdExe;
  private final RoleMenuUpdateCmdExe roleMenuUpdateCmdExe;

  private static final Logger log = LoggerFactory.getLogger(AdminRoleServiceImpl.class);


  @Override
  public PageResult<RoleCO> pageRole(PageRoleQryCmd cmd) {
    log.info("AdminRoleServiceImpl pageRole:{}", JSON.toJSONString(cmd));
    return rolePageQryExe.execute(cmd);
  }

  @Override
  public List<RoleCO> list() {
    return roleAllQryExe.execute();
  }

  @Override
  public RoleCO get(RoleIdCmd cmd) {
    log.info("AdminRoleServiceImpl get:{}", JSON.toJSONString(cmd));
    return roleSingleQryExe.execute(cmd);
  }

  @Override
  public void add(RoleCmd cmd) {
    log.info("AdminRoleServiceImpl add:{}", JSON.toJSONString(cmd));
    roleAddCmdExe.execute(cmd);
  }

  @Override
  public void update(RoleCmd cmd) {
    log.info("AdminRoleServiceImpl update:{}", JSON.toJSONString(cmd));
    roleUpdateCmdExe.execute(cmd);
  }

  @Override
  public void remove(RoleIdCmd cmd) {
    roleRemoveCmdExe.execute(cmd);
  }

  @Override
  public void updateRoleMenus(RoleMenuUpdateCmd cmd) {
    roleMenuUpdateCmdExe.execute(cmd);
  }
}
