package com.yami.shop.platform.controller.hb;

import com.alibaba.fastjson.JSONObject;
import com.yami.shop.bean.model.FrontCategory;
import com.yami.shop.common.util.hb.HBR;
import com.yami.shop.service.hb.IHBFrontCategoryService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 海博-前台类目管理
 *
 * @author fubojin
 * @version 1.0.0
 * @since 2025-09-01
 */
@Slf4j
@RestController
@RequestMapping("/hb/front")
@AllArgsConstructor
@CrossOrigin
public class FrontCategoryController {

    private final IHBFrontCategoryService frontCategoryService;

    /**
     * 海博新增前台类目信息-回调
     *
     * @param HBRequest 海博前台类目请求参数
     * @return 前台类目响应
     */
    @PostMapping("/add")
    public HBR addCategory(@RequestBody JSONObject HBRequest) {
        log.info("海博新增前台类目{}",HBRequest);
        return frontCategoryService.addHBFrontCategory(HBRequest);
    }
    /**
     * 海博修改前台类目信息-回调
     *
     * @param HBRequest 修改海博前台类目请求参数
     * @return 海博前台类目变更响应
     */
    @PostMapping("/update")
    public HBR updateCategory(@RequestBody JSONObject HBRequest) {
        log.info("海博变更前台类目{}",HBRequest);
        return frontCategoryService.addHBFrontCategory(HBRequest);
    }

    /**
     * 海博删除前台类目信息-回调
     *
     * @param HBRequest 删除海博前台类目请求参数
     * @return 海博前台类目删除响应
     */
    @PostMapping("/delete")
    public HBR deleteFrontCategory(@RequestBody JSONObject HBRequest) {
        log.info("海博删除前台类目{}",HBRequest);
        frontCategoryService.deleteFrontCategory(HBRequest);
        return HBR.success();
    }


    /**
     * 通过门店shopId和hbShopId同步全部前台类目
     */
    @GetMapping("/sync")
    public void sync(Long shopId, Long hbShopId) {
        frontCategoryService.sync(shopId, hbShopId);
    }

}
