package com.red.circle.other.app.service.family;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.command.family.ApplyJoinFamilyExe;
import com.red.circle.other.app.command.family.FamilyAdminExe;
import com.red.circle.other.app.command.family.FamilyBaseInfoExe;
import com.red.circle.other.app.command.family.FamilyCreateExe;
import com.red.circle.other.app.command.family.FamilyCreateRuleExe;
import com.red.circle.other.app.command.family.FamilyDailyTaskExe;
import com.red.circle.other.app.command.family.FamilyDismissGroupChatExe;
import com.red.circle.other.app.command.family.FamilyGetMembersExe;
import com.red.circle.other.app.command.family.FamilyGrantUserRoleExe;
import com.red.circle.other.app.command.family.FamilyGroupChatIsPayExe;
import com.red.circle.other.app.command.family.FamilyInfoEditExe;
import com.red.circle.other.app.command.family.FamilyLeaderboardExe;
import com.red.circle.other.app.command.family.FamilyLevelListExe;
import com.red.circle.other.app.command.family.FamilyMemberIdGetUserIdExe;
import com.red.circle.other.app.command.family.FamilyMemberListExe;
import com.red.circle.other.app.command.family.FamilyMessageHandleExe;
import com.red.circle.other.app.command.family.FamilyMessageListExe;
import com.red.circle.other.app.command.family.FamilyOnlineRoomExe;
import com.red.circle.other.app.command.family.FamilyPurchasingGroupChatExe;
import com.red.circle.other.app.command.family.FamilyRemoveUserExe;
import com.red.circle.other.app.command.family.FamilyRewardExe;
import com.red.circle.other.app.command.family.FamilyUserExitExe;
import com.red.circle.other.app.command.family.FamilyUserInfoExe;
import com.red.circle.other.app.command.family.ReceiveFamilyAwardExe;
import com.red.circle.other.app.dto.clientobject.family.FamilyBaseInfoCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyCreateRulesCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyLeaderboardCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyLevelParentCacheCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyMemberCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyMsgListCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyRewardCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyUserInfoCO;
import com.red.circle.other.app.dto.clientobject.room.RoomVoiceProfileCO;
import com.red.circle.other.app.dto.cmd.family.ApplyJoinFamilyCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyAdminQueryCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyBaseInfoQueryCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyCreateCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyDailyTaskCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyGrantUserRoleCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyGroupChatPayCheckCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyGroupChatQueryCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyInfoEditCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyMemberListCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyMemberListQueryCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyMessageHandleCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyMessageListCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyOnlineRoomQueryCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyRemoveUserCmd;
import com.red.circle.other.app.dto.cmd.family.FamilyUserInfoQueryCmd;
import com.red.circle.other.app.dto.cmd.family.ReceiveFamilyAwardCmd;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * Family.
 * </p>
 *
 * @author pengshigang
 * @since 2021-07-24
 */
@Service
@RequiredArgsConstructor
public class FamilyServiceImpl implements FamilyService {

  private final FamilyAdminExe familyAdminExe;
  private final FamilyCreateExe familyCreateExe;
  private final FamilyRewardExe familyRewardExe;
  private final FamilyUserInfoExe familyUserInfoExe;
  private final FamilyBaseInfoExe familyBaseInfoExe;
  private final FamilyInfoEditExe familyInfoEditExe;
  private final FamilyUserExitExe familyUserExitExe;
  private final ApplyJoinFamilyExe applyJoinFamilyExe;
  private final FamilyDailyTaskExe familyDailyTaskExe;
  private final FamilyLevelListExe familyLevelListExe;
  private final FamilyGetMembersExe familyGetMembersExe;
  private final FamilyMemberListExe familyMemberListExe;
  private final FamilyRemoveUserExe familyRemoveUserExe;
  private final FamilyOnlineRoomExe familyOnlineRoomExe;
  private final FamilyCreateRuleExe familyCreateRuleExe;
  private final FamilyMessageListExe familyMessageListExe;
  private final FamilyLeaderboardExe familyLeaderboardExe;
  private final ReceiveFamilyAwardExe receiveFamilyAwardExe;
  private final FamilyGrantUserRoleExe familyGrantUserRoleExe;
  private final FamilyMessageHandleExe familyMessageHandleExe;
  private final FamilyGroupChatIsPayExe familyGroupChatIsPayExe;
  private final FamilyDismissGroupChatExe familyDismissGroupChatExe;
  private final FamilyMemberIdGetUserIdExe familyMemberIdGetUserIdExe;
  private final FamilyPurchasingGroupChatExe familyPurchasingGroupChatExe;

  @Override
  public Long create(FamilyCreateCmd cmd) {
    return familyCreateExe.execute(cmd);
  }

  @Override
  public void edit(FamilyInfoEditCmd cmd) {
    familyInfoEditExe.execute(cmd);
  }

  @Override
  public FamilyMemberCO getAdmin(FamilyAdminQueryCmd cmd) {
    return familyAdminExe.execute(cmd);
  }

  @Override
  public List<FamilyMemberCO> listMember(FamilyMemberListQueryCmd cmd) {
    return familyMemberListExe.execute(cmd);
  }

  @Override
  public FamilyBaseInfoCO getBaseInfo(FamilyBaseInfoQueryCmd cmd) {
    return familyBaseInfoExe.execute(cmd);
  }

  @Override
  public void grantUserRole(FamilyGrantUserRoleCmd cmd) {
    if (Objects.equals(cmd.getRoleKey(), "REMOVE")) {

      Long userId = familyMemberIdGetUserIdExe.execute(cmd.getAuthorizedMemberId());
      if (Objects.isNull(userId)) {
        return;
      }
      FamilyRemoveUserCmd removeUserCmd = new FamilyRemoveUserCmd();
      removeUserCmd.setRemoveMemberId(userId);
      familyRemoveUserExe.execute(removeUserCmd);
      return;
    }
    familyGrantUserRoleExe.execute(cmd);
  }

  @Override
  public FamilyLeaderboardCO getLeaderboard(AppExtCommand cmd) {
    return familyLeaderboardExe.execute(cmd);
  }

  @Override
  public List<FamilyLevelParentCacheCO> listLevelConfig(AppExtCommand cmd) {
    return familyLevelListExe.execute(cmd);
  }

  @Override
  public void messageHandle(FamilyMessageHandleCmd cmd) {
    familyMessageHandleExe.execute(cmd);
  }

  @Override
  public List<FamilyMsgListCO> listMessage(FamilyMessageListCmd cmd) {
    return familyMessageListExe.execute(cmd);
  }

  @Override
  public List<RoomVoiceProfileCO> listOnlineRoom(FamilyOnlineRoomQueryCmd cmd) {
    return familyOnlineRoomExe.execute(cmd);
  }

  @Override
  public void removeUser(FamilyRemoveUserCmd cmd) {
    familyRemoveUserExe.execute(cmd);
  }

  @Override
  public void userExit(AppExtCommand cmd) {
    familyUserExitExe.execute(cmd);
  }

  @Override
  public FamilyUserInfoCO memberUserInfo(FamilyUserInfoQueryCmd cmd) {
    return familyUserInfoExe.execute(cmd);
  }

  @Override
  public void applyJoin(ApplyJoinFamilyCmd cmd) {
    applyJoinFamilyExe.execute(cmd);
  }

  @Override
  public void triggerDailyTask(FamilyDailyTaskCmd cmd) {
    familyDailyTaskExe.execute(cmd);
  }

  @Override
  public FamilyCreateRulesCO familyCreateRule(AppExtCommand cmd) {
    return familyCreateRuleExe.execute(cmd);
  }

  @Override
  public FamilyRewardCO myFamilyReward(AppExtCommand cmd) {
    return familyRewardExe.execute(cmd);
  }

  @Override
  public void receiveFamilyAward(ReceiveFamilyAwardCmd cmd) {
    receiveFamilyAwardExe.execute(cmd);
  }

  @Override
  public BigDecimal purchasingFamilyGroupChat(FamilyGroupChatQueryCmd cmd) {
    return familyPurchasingGroupChatExe.execute(cmd);
  }

  @Override
  public void dismissFamilyGroupChat(FamilyGroupChatQueryCmd cmd) {

    familyDismissGroupChatExe.execute(cmd);
  }

  @Override
  public Boolean getFamilyGroupChatIsPay(FamilyGroupChatPayCheckCmd cmd) {
    return familyGroupChatIsPayExe.execute(cmd);
  }

  @Override
  public List<FamilyMemberCO> getMembers(FamilyMemberListCmd cmd) {
    return familyGetMembersExe.execute(cmd);
  }

}
