package com.red.circle.other.app.inner.endpoint.team;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.team.TeamProfileClientService;
import com.red.circle.other.inner.endpoint.team.target.api.TeamProfileClientApi;
import com.red.circle.other.inner.model.cmd.team.AddTeamContactCmd;
import com.red.circle.other.inner.model.cmd.team.AddTeamRemarkCmd;
import com.red.circle.other.inner.model.cmd.team.StatusTeamBatchCmd;
import com.red.circle.other.inner.model.cmd.team.TeamApplicationProcessApprovalCmd;
import com.red.circle.other.inner.model.cmd.team.TeamApplicationProcessApprovalQryCmd;
import com.red.circle.other.inner.model.cmd.team.TeamApplicationProcessChangeCmd;
import com.red.circle.other.inner.model.cmd.team.TeamApplicationProcessQryCmd;
import com.red.circle.other.inner.model.cmd.team.TeamChangeOwnerCmd;
import com.red.circle.other.inner.model.cmd.team.TeamCreateCmd;
import com.red.circle.other.inner.model.cmd.team.TeamSalaryBackQryCmd;
import com.red.circle.other.inner.model.cmd.team.TeamTableQryCmd;
import com.red.circle.other.inner.model.cmd.team.TeamUpdateCmd;
import com.red.circle.other.inner.model.dto.agency.agency.TeamApplicationProcessApprovalDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamApplicationProcessDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamMemberDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamProfileDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamSalaryPaymentDTO;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 成员资料.
 *
 * @author pengliang on 2023/8/19
 */
@Validated
@RestController
@RequestMapping(value = TeamProfileClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class TeamProfileClientEndpoint implements TeamProfileClientApi {

  private final TeamProfileClientService teamProfileClientService;


  @Override
  public ResultResponse<List<TeamMemberDTO>> listByMemberIds(Set<Long> memberIds) {
    return ResultResponse.success(teamProfileClientService.listByMemberIds(memberIds));
  }

  @Override
  public ResultResponse<List<TeamProfileDTO>> listByIds(Set<Long> ids) {
    return ResultResponse.success(teamProfileClientService.listByIds(ids));
  }

  @Override
  public ResultResponse<TeamMemberDTO> getByMemberId(Long userId) {
    return ResultResponse.success(teamProfileClientService.getByMemberId(userId));
  }

  @Override
  public ResultResponse<List<TeamApplicationProcessApprovalDTO>> listProcessApprovalByCondition(
      TeamApplicationProcessApprovalQryCmd query) {
    return ResultResponse.success(teamProfileClientService.listProcessApprovalByCondition(query));
  }

  @Override
  public ResultResponse<List<TeamApplicationProcessDTO>> listProcessByCondition(
      TeamApplicationProcessQryCmd query) {
    return ResultResponse.success(teamProfileClientService.listProcessByCondition(query));
  }

  @Override
  public ResultResponse<Void> changeApplicationProcessStatus(
      TeamApplicationProcessChangeCmd param) {
    teamProfileClientService.changeApplicationProcessStatus(param);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<TeamApplicationProcessDTO> getApplicationProcessById(Long id) {
    return ResultResponse.success(teamProfileClientService.getApplicationProcessById(id));
  }


  @Override
  public ResultResponse<TeamApplicationProcessApprovalCmd> addApplicationProcessApproval(
      TeamApplicationProcessApprovalCmd param) {
    return ResultResponse.success(teamProfileClientService.addApplicationProcessApproval(
        param));
  }


  @Override
  public ResultResponse<Void> incrCounterMember(Long id) {
    teamProfileClientService.incrCounterMember(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> createTeam(TeamCreateCmd cmd) {
    teamProfileClientService.createTeam(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateTeam(TeamUpdateCmd cmd) {
    teamProfileClientService.updateTeam(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> updateTeamStatusBackBatch(StatusTeamBatchCmd cmd) {
    teamProfileClientService.updateTeamStatusBackBatch(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> delTeam(List<Long> teamIds) {
    teamProfileClientService.delTeam(teamIds);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<TeamProfileDTO>> teamList(TeamTableQryCmd cmd) {
    return ResultResponse.success(teamProfileClientService.teamList(cmd));
  }

  @Override
  public ResultResponse<Void> addTeamRemarks(AddTeamRemarkCmd cmd) {
    teamProfileClientService.addTeamRemarks(cmd.getTeamId(), cmd.getTeamRemark());
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeTeamRemarks(Long teamId, String remarkId) {
    teamProfileClientService.removeTeamRemarks(teamId, remarkId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addTeamContact(AddTeamContactCmd cmd) {
    teamProfileClientService.addTeamContact(cmd.getTeamId(), cmd.getTeamContact());
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> removeTeamContact(Long teamId, String contactId) {
    teamProfileClientService.removeTeamContact(teamId, contactId);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<String> getTeamRegionId(Long id) {
    return ResultResponse.success(teamProfileClientService.getTeamRegionId(id));
  }

  @Override
  public ResultResponse<Long> changeTeamOwnUser(TeamChangeOwnerCmd param) {
    return ResultResponse.success(teamProfileClientService.changeTeamOwnUser(param));
  }

  @Override
  public ResultResponse<PageResult<TeamSalaryPaymentDTO>> listByCondition(
      TeamSalaryBackQryCmd cmd) {
    return ResultResponse.success(teamProfileClientService.listByCondition(cmd));
  }

  @Override
  public ResultResponse<Set<Long>> listIdByRegion(String regionId) {
    return ResultResponse.success(teamProfileClientService.listIdByRegion(regionId));
  }

  @Override
  public ResultResponse<List<TeamProfileDTO>> listRegionAll(String region) {
    return ResultResponse.success(teamProfileClientService.listRegionAll(region));
  }

  @Override
  public ResultResponse<Long> getOwnUserIdById(Long id) {
    return ResultResponse.success(teamProfileClientService.getOwnUserIdById(id));
  }
}
