/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.platform.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.CategoryProd;
import com.yami.shop.bean.param.CategoryProductDTO;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.common.util.R;
import com.yami.shop.service.CategoryProdService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 门店分类绑定商品管理
 *
 * @author fbj
 * @version 1.0.0
 * @since 2025-9-26
 */
@RestController
@RequestMapping("/platform/categoryProd")
public class CategoryPropController {

    @Autowired
    private CategoryProdService categoryProdService;

    /**
     * 通过code查询分类绑定商品
     */
    @GetMapping("/listByCode")
    public R<List<CategoryProd>> listByCode(CategoryProd categoryProd) {
        List<CategoryProd> list = categoryProdService.list(new LambdaQueryWrapper<CategoryProd>()
                .eq(CategoryProd::getCode, categoryProd.getCode())
                .eq(CategoryProd::getIsDelete, 0)
                .eq(ObjectUtil.isNotEmpty(categoryProd.getShopId()), CategoryProd::getShopId, categoryProd.getShopId()));
        return R.SUCCESS(list);
    }


    /**
     * 分页通过code查询分类绑定商品
     */
    @GetMapping("/pageByCode")
    public R<IPage<CategoryProd>> pageByCode(CategoryProd categoryProd, PageParam<CategoryProd> page) {
        IPage<CategoryProd> list = categoryProdService.pageByCode(categoryProd, page);
        return R.SUCCESS(list);
    }


    /**
     * 绑定分类商品
     */
    @PostMapping("/categoryProduct")
    @ApiOperation(value = "绑定门店分类商品", notes = "绑定门店分类商品")
    public R categoryProduct(@Valid @RequestBody CategoryProductDTO categoryProductDTO) {
        categoryProdService.categoryProduct(categoryProductDTO);
        return R.SUCCESS("绑定商品成功");
    }

    /**
     * 取消分类绑定商品
     */
    @PostMapping("/cancelCategoryProduct")
    @ApiOperation(value = "取消分类绑定商品", notes = "取消分类绑定商品")
    public R cancelCategoryProduct(@Valid @RequestBody CategoryProductDTO categoryProductDTO) {
        categoryProdService.cancelCategoryProduct(categoryProductDTO);
        return R.SUCCESS();
    }
}
