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

import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.inner.service.sys.SysCpCabinConfigClientService;
import com.red.circle.other.infra.convertor.sys.SysCpCabinConfigConvertor;
import com.red.circle.other.infra.database.rds.entity.sys.SysCpCabinConfig;
import com.red.circle.other.infra.database.rds.service.sys.SysCpCabinConfigService;
import com.red.circle.other.inner.model.cmd.sys.SysCpCabinConfigQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysCpCabinConfigDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * CP小屋配置
 *
 * @author zongpubin on 2024/1/29
 */
@Service
@RequiredArgsConstructor
public class SysCpCabinConfigClientServiceImpl implements SysCpCabinConfigClientService {

  private final SysCpCabinConfigService sysCpCabinConfigService;
  private final SysCpCabinConfigConvertor sysCpCabinConfigConvertor;

  @Override
  public PageResult<SysCpCabinConfigDTO> getCpCabin(SysCpCabinConfigQryCmd query) {
    PageResult<SysCpCabinConfig> pageResult = sysCpCabinConfigService.getCpCabin(query);
    return pageResult.convert(sysCpCabinConfigConvertor::toSysCpCabinConfigDTO);
  }

  @Override
  public void addCpCabin(SysCpCabinConfigDTO param) {
    ResponseAssert.isTrue(CommonErrorCode.SAVE_FAILURE,
        sysCpCabinConfigService.save(sysCpCabinConfigConvertor.toSysCpCabinConfig(param)));
  }

  @Override
  public void removeCpCabin(Long id) {
    sysCpCabinConfigService.removeCpCabin(id);
  }

  @Override
  public void updateCpCabin(SysCpCabinConfigDTO param) {
    ResponseAssert.isTrue(CommonErrorCode.UPDATE_FAILURE,
        sysCpCabinConfigService.updateSelectiveById(
            sysCpCabinConfigConvertor.toSysCpCabinConfig(param)));
  }
}
