package shop.alien.storeplatform.controller;

import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.StoreInfo;
import shop.alien.entity.store.dto.StoreInfoDto;
import shop.alien.entity.store.vo.StoreMainInfoVo;
import shop.alien.storeplatform.service.StorePlatformInfoService;

@Slf4j
@Api(tags = {"商户平台-门店信息"})
@ApiSort(1)
@CrossOrigin
@RestController
@RequestMapping("/storePlatformInfo")
@RequiredArgsConstructor
public class StorePlatformInfoController {

    private final StorePlatformInfoService storePlatformInfoService;

    @ApiOperation("门店装修-编辑门店信息")
    @ApiOperationSupport(order = 3)
    @PostMapping("/saveOrUpdate")
    public R<StoreInfo> saveOrUpdate(@RequestBody StoreInfoDto storeInfo) {
        log.info("StoreInfoController.saveOrUpdate?storeInfo={}", storeInfo);
        try {
            int num = storePlatformInfoService.saveOrUpdateStoreInfo(storeInfo);
            if (num > 0) {
                return R.success("成功");
            }
            return R.fail("失败");
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    @ApiOperation(value = "门店详细信息")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "门店id", dataType = "Long", paramType = "query", required = true)})
    @GetMapping("/getDetail")
    public R<StoreMainInfoVo> getDetail(Integer id) {
        log.info("StoreInfoController.getDetail?id={}", id);
        return R.data(storePlatformInfoService.getDetail(id));
    }

}
