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.convertor.sys.SysGiftPackInnerConvertor;
import com.red.circle.other.app.inner.service.sys.SysGiftPackClientService;
import com.red.circle.other.infra.database.rds.entity.gift.GiftPack;
import com.red.circle.other.infra.database.rds.service.gift.GiftPackService;
import com.red.circle.other.inner.model.cmd.sys.GiftPackQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysGiftPackDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author zongpubin on 2023/11/1
 */
@Service
@RequiredArgsConstructor
public class SysGiftPackClientServiceImpl implements SysGiftPackClientService {

  private final GiftPackService giftPackService;
  private final SysGiftPackInnerConvertor sysGiftPackInnerConvertor;

  @Override
  public PageResult<SysGiftPackDTO> getGiftPackInfo(GiftPackQryCmd query) {
    PageResult<GiftPack> pageResult = giftPackService.getGiftPackInfo(query);
    return pageResult.convert(sysGiftPackInnerConvertor::toSysGiftPackDTO);
  }

  @Override
  public void addGiftPack(SysGiftPackDTO sysGiftPackDTO) {
    GiftPack sysGiftPack = sysGiftPackInnerConvertor.toGiftPack(sysGiftPackDTO);
    sysGiftPack.setDel(Boolean.FALSE);
    ResponseAssert.isTrue(CommonErrorCode.SAVE_FAILURE, giftPackService.save(sysGiftPack));
  }

  @Override
  public void updateGiftPack(SysGiftPackDTO sysGiftPackDTO) {
    ResponseAssert.isTrue(CommonErrorCode.UPDATE_FAILURE,
        giftPackService.updateSelectiveById(sysGiftPackInnerConvertor.toGiftPack(sysGiftPackDTO)));
  }

  @Override
  public void deleteGiftPack(Long id) {
    giftPackService.deleteGiftPack(id);
  }
}
