package com.cyksj.web.controller.manage.wholesale;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyksj.common.exception.BusinessRuntimeException;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.mapper.WebInfoMapper;
import com.cyksj.model.entity.WebInfo;
import com.cyksj.model.views.WebInfoView;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 批发网站管理
 * @author zwhui
 * @date 2025/6/16 12:07
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/manage/wholesale")
public class WholesaleController {

    private final WebInfoMapper webInfoMapper;

    /**
     * 查询店铺网站信息
     */
    @GetMapping("/list/webInfo")
    public Result<Page<WebInfoView>> getWebInfo(String prefix,Long wholesaleId,String shopName,Long userId,String nickName,Boolean status,@RequestParam(defaultValue = "1") Integer start,@RequestParam(defaultValue = "10") Integer limit) {
        log.info("查询店铺网站信息 prefix:{},wholesaleId:{},shopName:{},userId:{},nickName:{}",prefix,wholesaleId,shopName,userId,nickName);
        Page<WebInfoView> page = webInfoMapper.getWebInfo(new Page<>(start,limit),prefix,wholesaleId,shopName,userId,nickName,status);
        return GatewayResponse.SUCCESS.newBuilder().toResult(page);
    }


    /**
     * 上下架店铺
     */
    @PutMapping("/updStatus/{id}")
    public Result<Void> updateStatus(@PathVariable Long id) {
        WebInfo webInfo = webInfoMapper.selectById(id);
        if (webInfo == null) {
            throw new BusinessRuntimeException("店铺不存在");
        }
        webInfo.setStatus(!webInfo.getStatus());
        webInfoMapper.updateById(webInfo);
        return GatewayResponse.SUCCESS.newBuilder().toResult();
    }
}
