package com.red.circle.order.inner.endpoint;

import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.order.inner.endpoint.api.ProductClientApi;
import com.red.circle.order.inner.model.cmd.ProductConfigCmd;
import com.red.circle.order.inner.model.dto.ProductConfigDTO;
import com.red.circle.order.inner.model.dto.ProductConfigPackageDTO;
import com.red.circle.order.inner.service.ProductClientService;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 lisizhe on 2023/9/13
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = ProductClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
public class ProductClientEndpoint implements ProductClientApi {

  private final ProductClientService productClientService;

  /**
   * 根据条件获得产品信息
   */
  @Override
  public ResultResponse<Map<String, ProductConfigDTO>> mapByProductIds(ProductConfigCmd cmd) {
    return ResultResponse.success(
        productClientService.mapByProductIds(cmd.getSysOrigin(), cmd.getIsAndroid(),
            cmd.getProductIds()));
  }

  /**
   * 获取包名分组.
   */
  @Override
  public ResultResponse<Map<Long, List<ProductConfigPackageDTO>>> mapByProductCnfId(
      Set<Long> productCnfIds) {
    return ResultResponse.success(productClientService.mapByProductCnfId(productCnfIds));
  }
}
