package com.red.circle.other.app.inner.service.material.props.impl;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.inner.convertor.material.RoomThemeStoreInnerConvertor;
import com.red.circle.other.app.inner.service.material.props.RoomThemeStoreClientService;
import com.red.circle.other.infra.database.rds.entity.props.RoomThemeStore;
import com.red.circle.other.infra.database.rds.service.props.RoomThemeStoreService;
import com.red.circle.other.inner.model.cmd.material.RoomThemePageQryCmd;
import com.red.circle.other.inner.model.dto.material.RoomThemeStoreDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 道具商店.
 *
 * @author pengliang on 2023/12/4
 */
@Service
@RequiredArgsConstructor
public class RoomThemeStoreClientServiceImpl implements RoomThemeStoreClientService {

  private final RoomThemeStoreService roomThemeStoreService;
  private final RoomThemeStoreInnerConvertor roomThemeStoreInnerConvertor;

  @Override
  public PageResult<RoomThemeStoreDTO> pageOps(RoomThemePageQryCmd pageQryCmd) {
    return roomThemeStoreService.query()
        .orderByDesc(RoomThemeStore::getUpdateTime)
        .page(pageQryCmd.getPageQuery())
        .convert(roomThemeStoreInnerConvertor::toRoomThemeStoreDTO);
  }

  @Override
  public boolean updateRoomTheme(RoomThemeStoreDTO dto) {
    return roomThemeStoreService.updateSelectiveById(
        roomThemeStoreInnerConvertor.toRoomThemeStore(dto));
  }

  @Override
  public boolean addRoomTheme(RoomThemeStoreDTO dto) {
    return roomThemeStoreService.save(
        roomThemeStoreInnerConvertor.toRoomThemeStore(dto));
  }

}
