package com.red.circle.console.adapter.app.sys;


import com.red.circle.common.business.core.ControllerRedisKeyConstant;
import com.red.circle.console.app.service.app.sys.SysCountryCodeService;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.inner.model.cmd.sys.SysCountryCodeCmd;
import com.red.circle.other.inner.model.cmd.sys.SysCountryCodePageQryCmd;
import com.red.circle.other.inner.model.dto.sys.SysCountryCodeDTO;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 国家列表
 *
 * @author houyong
 * @since 2020-08-11
 */
@RestController
@RequestMapping("/sys/country/code")
@RequiredArgsConstructor
public class SysCountryCodeRestController extends BaseController {

  private final SysCountryCodeService sysCountryCodeService;

  /**
   * 国家列表.
   */
  @GetMapping
  public List<SysCountryCodeDTO> listContent() {
    return sysCountryCodeService.listContent();
  }

  /**
   * 国家管理列表.
   */
  @GetMapping("/page")
  public PageResult<SysCountryCodeDTO> sysCountryCodePage(SysCountryCodePageQryCmd query) {
    return sysCountryCodeService.sysCountryCodePage(query);
  }

  /**
   * 修改国家列表.
   */
  @Caching(evict = {
      @CacheEvict(value = ControllerRedisKeyConstant.COUNTRY, key = "'"
          + ControllerRedisKeyConstant.COUNTRY_TOP_SIX + "'"),
      @CacheEvict(value = ControllerRedisKeyConstant.COUNTRY, key = "'"
          + ControllerRedisKeyConstant.APP_COUNTRY_CODE + "'")
  })
  @PutMapping
  public void updateCountryCode(@RequestBody SysCountryCodeCmd cmd) {
    cmd.setUpdateUser(cmd.getReqUserId());
    sysCountryCodeService.updateCountryCode(cmd);
  }

}
