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

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.team.TeamBillCycleClientService;
import com.red.circle.other.inner.endpoint.team.target.api.TeamBillCycleClientApi;
import com.red.circle.other.inner.model.cmd.team.AddTeamRemarkCmd;
import com.red.circle.other.inner.model.cmd.team.TeamBillByConditionQryCmd;
import com.red.circle.other.inner.model.cmd.team.TeamBillCycleBackQryCmd;
import com.red.circle.other.inner.model.cmd.team.TeamCalculatorWorkCmd;
import com.red.circle.other.inner.model.cmd.team.TeamMemberTargetResetCmd;
import com.red.circle.other.inner.model.dto.agency.agency.TeamBillAnchorStatisticsModelDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamBillCycleDTO;
import com.red.circle.other.inner.model.dto.agency.agency.TeamCalculatorWorkResultDTO;
import com.red.circle.other.inner.enums.team.TeamBillCycleStatus;
import java.util.List;
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/10/17
 */
@Validated
@RestController
@RequestMapping(value = TeamBillCycleClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class TeamBillCycleClientEndpoint implements TeamBillCycleClientApi {

  private final TeamBillCycleClientService teamBillCycleClientService;

  @Override
  public ResultResponse<Long> getLatestBillIdByTeamId(Long teamId) {
    return ResultResponse.success(teamBillCycleClientService.getLatestBillIdByTeamId(teamId));
  }

  @Override
  public ResultResponse<List<TeamBillCycleDTO>> listBillTable(TeamBillCycleBackQryCmd query) {
    return ResultResponse.success(teamBillCycleClientService.listBillTable(query));
  }


  @Override
  public ResultResponse<TeamCalculatorWorkResultDTO> calculatorWork(TeamCalculatorWorkCmd param) {
    return ResultResponse.success(teamBillCycleClientService.calculatorWork(param));
  }

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

  @Override
  public ResultResponse<Void> removeInternalRemarks(Long id, String remarkId) {
    teamBillCycleClientService.removeInternalRemarks(id, remarkId);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<Void> updateRemarks(Long id, String remarks) {
    teamBillCycleClientService.updateRemarks(id, remarks);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<Void> updateStatus(Long billId, TeamBillCycleStatus status,
      Long updateUser) {
    teamBillCycleClientService.updateStatus(billId, status, updateUser);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<List<TeamBillAnchorStatisticsModelDTO>> queryTeamBillByCondition(
      TeamBillByConditionQryCmd cmd) {
    return ResultResponse.success(
        teamBillCycleClientService.queryTeamBillByCondition(cmd));
  }

  @Override
  public ResultResponse<Void> resetUnpaidBillMemberTarget(TeamMemberTargetResetCmd param) {
    teamBillCycleClientService.resetUnpaidBillMemberTarget(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> refreshUnpaidBills(TeamBillCycleBackQryCmd query) {
    teamBillCycleClientService.refreshUnpaidBills(query);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<TeamBillCycleDTO> getBillByTeamId(Long teamId) {
    return ResultResponse.success(teamBillCycleClientService.getBillByTeamId(teamId));
  }

}
