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

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.framework.mybatis.constant.PageConstant;
import com.red.circle.other.app.inner.service.sys.ApiOperationLogClientService;
import com.red.circle.other.app.inner.service.sys.SysOperationIncomeExpenditureClientService;
import com.red.circle.other.infra.database.mongo.entity.sys.query.ApiOperationLogQuery;
import com.red.circle.other.inner.endpoint.sys.api.ApiOperationLogClientApi;
import com.red.circle.other.inner.model.cmd.sys.SysOperationIncomeExpenditureCmd;
import com.red.circle.other.inner.model.cmd.tools.ApiOperationLogCmd;
import com.red.circle.other.inner.model.dto.sys.ApiOperationLogDTO;

import java.util.List;
import java.util.Map;
import java.util.Objects;
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/9/20
 */
@Validated
@RestController
@RequestMapping(value = ApiOperationLogClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class ApiOperationLogClientEndpoint implements ApiOperationLogClientApi {

  private final ApiOperationLogClientService apiRequestLogClientService;
  private final SysOperationIncomeExpenditureClientService operationIncomeExpenditureClientService;

  @Override
  public ResultResponse<Void> add(ApiOperationLogDTO log) {
    apiRequestLogClientService.add(log);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<Void> addSysOperationIncome(SysOperationIncomeExpenditureCmd cmd) {
    operationIncomeExpenditureClientService.saveSysOperationIncome(cmd);
    return ResultResponse.success();
  }


  @Override
  public ResultResponse<Map<String, String>> mapAssociateRemarks(Set<String> associateIds) {
    return ResultResponse.success(
        operationIncomeExpenditureClientService.mapAssociateRemarks(associateIds));
  }

  @Override
  public ResultResponse<List<ApiOperationLogDTO>> list(ApiOperationLogCmd cmd) {
    if (Objects.isNull(cmd.getSize())) {
      cmd.setSize(PageConstant.DEFAULT_LIMIT_SIZE);
    }
    return ResultResponse.success(apiRequestLogClientService.list(cmd));
  }
}
