package com.red.circle.other.app.inner.endpoint.material.props;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.material.props.PropsSourceClientService;
import com.red.circle.other.inner.endpoint.material.props.api.PropsSourceClientApi;
import com.red.circle.other.inner.model.cmd.material.PropsResourcesMergeCmd;
import com.red.circle.other.inner.model.cmd.material.PropsSourceRecordQryCmd;
import com.red.circle.other.inner.model.dto.material.PropsRedPacketSkinDTO;
import com.red.circle.other.inner.model.dto.material.PropsResourcesDTO;
import com.red.circle.other.inner.model.dto.material.PropsResourcesMergeDTO;
import java.util.List;
import java.util.Map;
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/11/7
 */
@Validated
@RestController
@RequestMapping(value = PropsSourceClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class PropsSourceClientEndpoint implements PropsSourceClientApi {

  private final PropsSourceClientService propsSourceClientService;

  @Override
  public ResultResponse<PropsResourcesDTO> getById(Long id) {
    return ResultResponse.success(propsSourceClientService.getById(id));
  }

  @Override
  public ResultResponse<Map<Long, PropsResourcesDTO>> mapByIds(Set<Long> ids) {
    return ResultResponse.success(propsSourceClientService.mapByIds(ids));
  }

  @Override
  public ResultResponse<PropsResourcesMergeDTO> mapMergeByIds(PropsResourcesMergeCmd cmd) {
    return ResultResponse.success(propsSourceClientService.mapMergeByIds(cmd));
  }


  @Override
  public ResultResponse<List<PropsResourcesDTO>> listSysOrigin(String sysOrigin, String type) {
    return ResultResponse.success(
        propsSourceClientService.listSysOriginPropsResources(sysOrigin, type));
  }

  @Override
  public ResultResponse<List<PropsResourcesDTO>> listExcludeFamily(String sysOrigin, String type) {
    return ResultResponse.success(
        propsSourceClientService.listExcludeFamily(sysOrigin, type));
  }

  @Override
  public ResultResponse<Void> offShelfPropsResources(Long id, Boolean offShelf) {
    propsSourceClientService.offShelfPropsResources(id, offShelf);

    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PageResult<PropsResourcesDTO>> pagePropsResourcesOps(
      PropsSourceRecordQryCmd qryCmd) {
    return ResultResponse.success(propsSourceClientService.pagePropsResourcesOps(qryCmd));
  }

  @Override
  public ResultResponse<Void> addOrUpdatePropsResources(PropsResourcesDTO dto) {
    propsSourceClientService.addOrUpdatePropsResources(dto);
//      if (dto.getAdminFree()) {
//
//      }
//            propsSourceClientService.updateRedisCache(dto);

    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PropsRedPacketSkinDTO> getPropsRedPacketSkin(Long id) {
    return ResultResponse.success(propsSourceClientService.getPropsRedPacketSkin(id));
  }

}
