package com.red.circle.other.app.inner.service.approval.impl;

import com.red.circle.common.business.core.enums.DataApprovalTypeEnum;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.inner.service.approval.ApprovalUserSettingInfoClientService;
import com.red.circle.other.infra.database.rds.entity.approval.ApprovalUserSettingData;
import com.red.circle.other.infra.database.rds.service.approval.ApprovalUserSettingDataService;
import com.red.circle.other.inner.model.cmd.approval.ApprovalProfileDescQryCmd;
import com.red.circle.other.inner.model.cmd.approval.ApprovalUserProfileQryCmd;
import com.red.circle.other.inner.model.dto.approval.ApprovalProfileDescDTO;
import com.red.circle.other.inner.model.dto.approval.ApprovalUserProfileDTO;
import com.red.circle.tool.core.collection.CollectionUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 用户审批相关列表
 *
 * @author zongpubin on 2024/1/22
 */
@Service
@RequiredArgsConstructor
public class ApprovalUserSettingInfoClientServiceImpl implements
    ApprovalUserSettingInfoClientService {

  private final ApprovalUserSettingDataService approvalUserSettingDataService;


  @Override
  public PageResult<ApprovalProfileDescDTO> pageProfileDescApproval(
      ApprovalProfileDescQryCmd query) {
    query.setApproveType(DataApprovalTypeEnum.PROFILE_DESC.name());

    PageResult<ApprovalUserSettingData> pageResult = approvalUserSettingDataService.pageFamilyApproval(
        query);

    if (CollectionUtils.isEmpty(pageResult.getRecords())) {
      return pageResult.convert(approvalUserSettingData -> new ApprovalProfileDescDTO());
    }

    return pageResult.convert(approvalUserSettingData -> new ApprovalProfileDescDTO().setUserId(approvalUserSettingData.getUserId()));
  }

  @Override
  public PageResult<ApprovalUserProfileDTO> pageUserProfileApproval(
      ApprovalUserProfileQryCmd query) {
    return approvalUserSettingDataService.pageUserProfileApproval(query);

  }
}
