package com.cool.store.controller.webc;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.context.LoginUserInfo;
import com.cool.store.entity.EnterpriseUserDO;
import com.cool.store.enums.UserRoleEnum;
import com.cool.store.request.SysStoreAppRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.SysStoreAppResponse;
import com.cool.store.service.SysStoreAppService;
import com.cool.store.service.UserAuthMappingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mini/sysStore")
@Api(tags = "mini系统建店")
@Slf4j
public class MiniSysStoreAppController {

    @Resource
    private SysStoreAppService sysStoreAppService;


    @Resource
    UserAuthMappingService userAuthMappingService;

    @PostMapping(path = "/submit")
    @ApiOperation("提交(更新) 系统建店申请")
    public ResponseResult submitSysBuildStore(@RequestBody SysStoreAppRequest request) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return sysStoreAppService.submitSysBuildStore(request,user);
    }

    @GetMapping(path = "/default/get")
    @ApiOperation("获取系统建店默认值")
    public ResponseResult<SysStoreAppResponse> getDefaultValueSysBuildStore(@RequestParam("lineId") Long lineId,
                                                                            @RequestParam("shopId") Long shopId) {
        LoginUserInfo user = CurrentUserHolder.getUser();
        return ResponseResult.success(sysStoreAppService.getDefaultValueSysBuildStore(lineId,shopId,user));
    }

    @GetMapping(path = "/getSmallRegionDD")
    @ApiOperation("获取小区督导")
    public ResponseResult<EnterpriseUserDO> getSmallRegionDD(@RequestParam("regionId") Long regionId) {
        return ResponseResult.success(userAuthMappingService.hierarchicalSearch(UserRoleEnum.SUPERVISION, regionId));
    }

}
