package com.red.circle.other.app.inner.endpoint.sys;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.inner.service.sys.BadgeConfigClientService;
import com.red.circle.other.inner.endpoint.sys.api.SysBadgeConfigClientApi;
import com.red.circle.other.inner.enums.sys.SysBadgeConfigTypeEnum;
import com.red.circle.other.inner.model.cmd.sys.GiveBadgeConfigQryCmd;
import com.red.circle.other.inner.model.cmd.sys.SysBadgeConfigQryCmd;
import com.red.circle.other.inner.model.cmd.sys.SysBadgePictureConfigParamCmd;
import com.red.circle.other.inner.model.dto.material.BadgeConfigDTO;
import com.red.circle.other.inner.model.dto.material.BadgePictureConfigDTO;
import com.red.circle.other.inner.model.dto.sys.GiveBadgeConfigDTO;
import com.red.circle.other.inner.model.dto.sys.SelectBadgeDTO;
import com.red.circle.other.inner.model.dto.sys.SysBadgeConfigInfoDTO;
import java.util.List;
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/8/11
 */
@Validated
@RestController
@RequestMapping(value = SysBadgeConfigClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class SysBadgeConfigClientEndpoint implements SysBadgeConfigClientApi {

  private final BadgeConfigClientService badgeConfigClientService;

  @Override
  public ResultResponse<List<SelectBadgeDTO>> listBadgeByType(SysBadgeConfigTypeEnum type) {
    return ResultResponse.success(badgeConfigClientService.listBadgeByType(type));
  }

  @Override
  public ResultResponse<PageResult<SysBadgeConfigInfoDTO>> getBadgeConfig(SysBadgeConfigQryCmd query) {
    return ResultResponse.success(badgeConfigClientService.getBadgeConfig(query));
  }

  @Override
  public ResultResponse<Void> updateBadgeConfig(BadgeConfigDTO badgeConfigDTO) {
    badgeConfigClientService.updateBadgeConfig(badgeConfigDTO);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addBadgeConfig(BadgeConfigDTO badgeConfigDTO) {
    badgeConfigClientService.addBadgeConfig(badgeConfigDTO);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> deleteBadge(Long id) {
    badgeConfigClientService.deleteBadge(id);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<BadgePictureConfigDTO>> listBadgePictureBySysOrigin(
      String sysOrigin, SysBadgeConfigTypeEnum type) {
    return ResultResponse.success(
        badgeConfigClientService.listBadgePictureBySysOrigin(sysOrigin, type));
  }

  @Override
  public ResultResponse<PageResult<GiveBadgeConfigDTO>> getGiveBadgePage(
      GiveBadgeConfigQryCmd query) {
    return ResultResponse.success(badgeConfigClientService.getGiveBadgePage(query));
  }

  @Override
  public ResultResponse<Void> addOrUpdateBadgePicture(SysBadgePictureConfigParamCmd param) {
    badgeConfigClientService.addOrUpdateBadgePicture(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<List<Long>> listAdminBadgeIds() {
    return ResultResponse.success(badgeConfigClientService.listAdminBadgeIds());
  }

  @Override
  public ResultResponse<Long> getAdminBadgeId(String roles) {
    return ResultResponse.success(badgeConfigClientService.getAdminBadgeId(roles));
  }

  @Override
  public ResultResponse<List<BadgePictureConfigDTO>> listBadgePictureByBadgeIds(List<Long> ids) {
    return ResultResponse.success(badgeConfigClientService.listBadgePictureByBadgeIds(ids));
  }

}
