package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.request.RegionAreaConfigAddRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.RegionAreaConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author wxp
 * @version 1.0
 */
@Api(tags = "区域配置")
@RestController
@RequestMapping("pc/regionAreaConfig")
public class RegionAreaConfigController {

    @Autowired
    private RegionAreaConfigService regionAreaConfigService;

    @ApiOperation(value = "区域配置省市")
    @PostMapping("/addRegionAreaConfig")
    public ResponseResult<Boolean> saveOrUpdateRegionAreaConfig(@Valid @RequestBody RegionAreaConfigAddRequest request) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(regionAreaConfigService.saveOrUpdateRegionAreaConfig(request, user));
    }

    @ApiOperation("根据战区id获取配置的省市列表")
    @GetMapping("/listAreaIdByRegionId")
    public ResponseResult<List<Long>> listAreaIdByRegionId(@RequestParam("regionId")Long regionId) {
        return ResponseResult.success(regionAreaConfigService.listAreaIdByRegionId(regionId));
    }

}
