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

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.ShopDetail;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.common.util.R;
import com.yami.shop.common.util.hb.HBR;
import com.yami.shop.service.hb.IStoreManagementService;
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/store")
@AllArgsConstructor
@CrossOrigin
public class StoreManagementController {

    private final IStoreManagementService storeManagementService;

    /**
     * 海博新增门店信息-回调
     *
     * @param HBRequest 门店新增请求参数
     * @return 门店新增响应
     */
    @PostMapping("/add")
    public HBR addRegisterStore(@RequestBody JSONObject HBRequest) {
        log.info("海博添加门店{}", HBRequest);
        return HBR.success(storeManagementService.updateRegisterStore(HBRequest));
    }

    /**
     * 海博修改门店信息-回调
     *
     * @param HBRequest 门店变更请求参数
     * @return 门店变更响应
     */
    @PostMapping("/update")
    public HBR updateRegisterStore(@RequestBody JSONObject HBRequest) {
        log.info("海博变更门店{}", HBRequest);
        return HBR.success(storeManagementService.updateRegisterStore(HBRequest));
    }

    /**
     * 条件获取门店列表信息
     */
    @GetMapping("/list")
    public R<List<ShopDetail>> list(@ModelAttribute ShopDetail shopDetail) {
        return R.SUCCESS(storeManagementService.list(shopDetail));
    }

    /**
     * 分页获取门店列表信息
     */
    @GetMapping("/page")
    public R<IPage<ShopDetail>> page(@ModelAttribute ShopDetail shopDetail, PageParam<ShopDetail> page) {
        IPage<ShopDetail> shopDetailPage = storeManagementService.page(shopDetail, page);
        return R.SUCCESS(shopDetailPage);
    }



    /**
     * 获取门店详情
     */
    @GetMapping("/detail/{id}")
    public R<ShopDetail> detail(@PathVariable("id") Long id ) {
        return R.SUCCESS(storeManagementService.detail(id));
    }


    /**
     * 更改门店经营状态
     */
    @PostMapping("/updateStatus")
    public R status(@RequestBody JSONObject HBRequest) {
        log.info("海博变更门店经营状态{}", HBRequest);
        storeManagementService.updateStatus(HBRequest);
        return R.SUCCESS();
    }
}
