
package com.tmerclub.cloud.multishop.controller.app;

import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.multishop.model.ShopRenovation;
import com.tmerclub.cloud.multishop.service.ShopRenovationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 店铺装修信息
 * @author Orange
 * @date 2022-08-12 11:27:18
 */
@RestController("appShopRenovationController")
@RequestMapping("/ua/shopRenovation")
@Tag(name = "app-店铺装修信息")
public class ShopRenovationController {
    private static final Logger logger = LoggerFactory.getLogger(ShopRenovationController.class);

    @Autowired
    private ShopRenovationService shopRenovationService;

    @GetMapping("/homePage")
    @Operation(summary = "获取店铺主页装修信息", description = "根据店铺id，装修类型获取店铺装修信息")
    @Parameters({
            @Parameter(name = "shopId", description = "店铺id", required = true),
            @Parameter(name = "renovationType", description = "装修类型 1.pc 2.移动端", required = true)
    })
    public ServerResponseEntity<ShopRenovation> homePage(@RequestParam("shopId") Long shopId,
                                                            @RequestParam("renovationType") Integer renovationType) {
        ShopRenovation shopHomeRenovation = shopRenovationService.getShopHomeRenovation(shopId, renovationType);
        return ServerResponseEntity.success(shopHomeRenovation);
    }

    @GetMapping("/getHome")
    @Operation(summary = "获取店铺主页装修信息(内容为空）", description = "根据店铺id，装修类型获取店铺装修信息(内容为空）")
    @Parameters({
            @Parameter(name = "shopId", description = "店铺id", required = true),
            @Parameter(name = "renovationType", description = "装修类型 1.pc 2.移动端", required = true)
    })
    public ServerResponseEntity<ShopRenovation> getHome(@RequestParam("shopId") Long shopId,
                                                        @RequestParam("renovationType") Integer renovationType) {
        ShopRenovation shopHomeRenovation = shopRenovationService.getShopHomeRenovation(shopId, renovationType);
        if (Objects.nonNull(shopHomeRenovation)) {
            logger.info("判断店铺装修信息是否为空，不为空则设置内容为空");
            shopHomeRenovation.setContent(null);
        }
        return ServerResponseEntity.success(shopHomeRenovation);
    }

    @GetMapping("/getRenovationById")
    @Operation(summary = "根据装修id获取店铺装修信息", description = "根据装修id获取店铺装修信息")
    @Parameter(name = "renovationId", description = "装修id", required = true)
    public ServerResponseEntity<ShopRenovation> getRenovationById(@RequestParam("renovationId") Long renovationId) {
        ShopRenovation shopRenovation = shopRenovationService.getByRenovationId(renovationId);
        return ServerResponseEntity.success(shopRenovation);
    }
}
