package com.starry.admin.modules.weichat.controller;

import com.starry.admin.common.aspect.ClerkUserLogin;
import com.starry.admin.modules.shop.module.entity.PlayShopArticleInfoEntity;
import com.starry.admin.modules.shop.module.entity.PlayShopCarouselInfoEntity;
import com.starry.admin.modules.shop.service.IPlayShopArticleInfoService;
import com.starry.admin.modules.shop.service.IPlayShopCarouselInfoService;
import com.starry.admin.modules.weichat.entity.PlayShopReadArticleVo;
import com.starry.admin.modules.weichat.entity.shop.ShopHomeCarouseInfoReturnVo;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 店铺接口
 *
 * @author admin
 * @since 2024/5/20 下午11:19
 **/
@Api(tags = "微信店铺接口", description = "微信端店铺相关接口")
@Slf4j
@RestController
@RequestMapping("/wx/shop")
public class WxShopController {

    @Resource
    private IPlayShopCarouselInfoService playShopCarouselInfoService;

    @Resource
    IPlayShopArticleInfoService playShopArticleInfoService;

    /**
     * 获取首页轮播图
     */
    @ApiOperation(value = "获取首页轮播图", notes = "获取店铺首页轮播图信息")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = ShopHomeCarouseInfoReturnVo.class, responseContainer = "List")})
    @GetMapping(value = "custom/getShopHomeCarouseInfo")
    public R getShopHomeCarouseInfo() {
        List<PlayShopCarouselInfoEntity> entities = playShopCarouselInfoService.selectHomeCarouselInfo();
        return R.ok(ConvertUtil.entityToVoList(entities, ShopHomeCarouseInfoReturnVo.class));
    }

    /**
     * 获取店铺文章列表
     */
    @ApiOperation(value = "获取文章列表", notes = "获取店铺所有文章列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = PlayShopArticleInfoEntity.class, responseContainer = "List")})
    @ClerkUserLogin
    @GetMapping(value = "clerk/getArticleList")
    public R getArticleList() {
        return R.ok(playShopArticleInfoService.selectByList());
    }

    /**
     * 阅读店铺文章
     */
    @ApiOperation(value = "阅读文章", notes = "阅读店铺文章并增加访问次数")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @ClerkUserLogin
    @GetMapping(value = "clerk/readShopArticleInfo")
    public R readShopArticleInfo(@ApiParam(value = "文章参数", required = true) @RequestBody PlayShopReadArticleVo vo) {
        PlayShopArticleInfoEntity entity = playShopArticleInfoService.selectById(vo.getId());
        entity.setVisitsNumber(entity.getVisitsNumber() + 1);
        playShopArticleInfoService.update(entity);
        return R.ok("成功");
    }

}
