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.AdministratorClientService;
import com.red.circle.other.inner.endpoint.sys.api.AdministratorClientApi;
import com.red.circle.other.inner.model.cmd.sys.AddSysAdministratorCmd;
import com.red.circle.other.inner.model.cmd.sys.AppUserDetailsQryCmd;
import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthCmd;
import com.red.circle.other.inner.model.cmd.sys.SysAdministratorAuthResourceCmd;
import com.red.circle.other.inner.model.cmd.sys.SysAdministratorChangeStatusCmd;
import com.red.circle.other.inner.model.dto.sys.AdministratorDTO;
import com.red.circle.other.inner.model.dto.sys.SysAdministratorAuthResourceDTO;
import com.red.circle.other.inner.model.dto.sys.SysAdministratorInfoDTO;
import java.util.List;
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/8/11
 */
@Validated
@RestController
@RequestMapping(value = AdministratorClientApi.API_PREFIX, produces = MediaType.APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
public class AdministratorClientEndpoint implements AdministratorClientApi {

  private final AdministratorClientService administratorClientService;

  @Override
  public ResultResponse<AdministratorDTO> getByUserId(Long userId) {
    return ResultResponse.success(administratorClientService.getByUserId(userId));
  }

  @Override
  public ResultResponse<Boolean> existsAvailable(Set<Long> userIds) {
    return ResultResponse.success(administratorClientService.existsAvailable(userIds));
  }


  @Override
  public ResultResponse<List<SysAdministratorAuthResourceDTO>> getSysAdministratorAuthResource() {
    return ResultResponse.success(administratorClientService.getSysAdministratorAuthResource());
  }


  @Override
  public ResultResponse<List<Long>> getSysAdministratorAuthResourceByUserId(Long userId) {
    return ResultResponse.success(
        administratorClientService.getSysAdministratorAuthResourceByUserId(userId));
  }

  @Override
  public ResultResponse<Void> updateSysAdministratorAuthResource(
      SysAdministratorAuthResourceCmd cmd) {
    administratorClientService.updateSysAdministratorAuthResource(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addSysAdministratorAuthResource(
      SysAdministratorAuthResourceCmd cmd) {
    administratorClientService.addSysAdministratorAuthResource(cmd);
    return ResultResponse.success();
  }

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

  @Override
  public ResultResponse<Void> deleteAndAddAdministratorAuth(SysAdministratorAuthCmd cmd) {
    administratorClientService.deleteAndAddAdministratorAuth(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> addSysAdministrator(AddSysAdministratorCmd cmd) {
    administratorClientService.addSysAdministrator(cmd);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<PageResult<SysAdministratorInfoDTO>> pageUserDetails(
      AppUserDetailsQryCmd appUserDetailsQuery) {
    return ResultResponse.success(administratorClientService.pageUserDetails(appUserDetailsQuery));
  }


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

  @Override
  public ResultResponse<Void> changeStatusAdministrator(SysAdministratorChangeStatusCmd param) {
    administratorClientService.changeStatusAdministrator(param);
    return ResultResponse.success();
  }

  @Override
  public ResultResponse<Void> changeRoles(Long id, String roles) {
    administratorClientService.changeRoles(id, roles);
    return ResultResponse.success();
  }
}
