package com.czg.controller.admin;

import com.czg.BaseQueryParam;
import com.czg.log.annotation.OperationLog;
import com.czg.market.dto.MkProductSmartSuggestDTO;
import com.czg.market.service.MkProductSmartSuggestService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.AssertUtil;
import com.czg.validator.group.DefaultGroup;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 点单智能推荐
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/suggest")
public class AProductSmartSuggestController {
    @Resource
    private MkProductSmartSuggestService suggestService;

    /**
     * 点单智能推荐-分页
     */
    @GetMapping("page")
    public CzgResult<Page<MkProductSmartSuggestDTO>> getProductSmartSuggestPage(BaseQueryParam param) {
        Page<MkProductSmartSuggestDTO> data = suggestService.getProductSmartSuggestPage(param, StpKit.USER.getShopId());
        return CzgResult.success(data);
    }


    /**
     * 点单智能推荐-新增
     */
    @PostMapping
    @OperationLog("点单智能推荐-新增")
    public CzgResult<Void> addProductSmartSuggest(@RequestBody @Validated({InsertGroup.class, DefaultGroup.class}) MkProductSmartSuggestDTO dto) {
        Long shopId = StpKit.USER.getShopId();
        dto.setShopId(shopId);
        suggestService.addProductSmartSuggest(dto);
        return CzgResult.success();
    }

    /**
     * 点单智能推荐-修改
     */
    @PutMapping
    @OperationLog("点单智能推荐-修改")
    public CzgResult<Void> updateProductSmartSuggest(@RequestBody @Validated({UpdateGroup.class, DefaultGroup.class}) MkProductSmartSuggestDTO dto) {
        Long shopId = StpKit.USER.getShopId();
        dto.setShopId(shopId);
        suggestService.updateProductSmartSuggestById(dto);
        return CzgResult.success();
    }

    /**
     * 点单智能推荐-删除
     */
    @DeleteMapping
    @OperationLog("点单智能推荐-删除")
    public CzgResult<String> deleteMkProductSmartSuggest(@RequestParam Long id) {
        AssertUtil.isNull(id, "{}不能为空", "id");
        suggestService.deleteProductSmartSuggest(id);
        return CzgResult.success();
    }


    /**
     * 获取点单智能推荐
     */
    @GetMapping
    public CzgResult<Map<String, Object>> getActivity(@RequestParam Long shopId) {
        Map<String, Object> map = suggestService.getProductSmartSuggestByShopId(shopId);
        return CzgResult.success(map);
    }

}
