package com.czg.controller.admin;

import com.czg.account.dto.pad.*;
import com.czg.account.entity.PadLayout;
import com.czg.account.service.PadLayoutService;
import com.czg.account.service.PadProdService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * pad点餐相关
 *
 * @author Administrator
 */
@RestController
@RequestMapping("admin/padProd")
public class PadProdController {
    @Resource
    private PadProdService padProdService;
    @Resource
    private PadLayoutService padLayoutService;

    /**
     * pad布局列表
     *
     * @return 数据
     */
    @SaAdminCheckPermission(parentName = "pad布局", value = "padProd:layout:list", name = "pad布局列表")
    @GetMapping("/layout")
    public CzgResult<Page<PadLayout>> layout() {
        return CzgResult.success(padLayoutService.page(PageUtil.buildPage()));
    }

    /**
     * 获取点餐列表
     *
     * @param productCategoryId 分类id
     * @return 数据
     */
    @SaAdminCheckPermission(parentName = "pad布局", value = "padProd:list", name = "pad点餐列表")
    @GetMapping
    public CzgResult<Page<PadProductCategoryDTO>> list(Long productCategoryId) {
        return CzgResult.success(padProdService.pageInfo(PageUtil.buildPage(), productCategoryId, StpKit.USER.getShopId()));
    }

    /**
     * 获取点餐详情
     *
     * @param id tb_pad_product_category Id
     * @return 数据
     */
    @SaAdminCheckPermission(parentName = "pad布局", value = "padProd:detail", name = "pad点餐详情")
    @GetMapping("/detail")
    public CzgResult<PadDetailDTO> detail(Long id) {
        return CzgResult.success(padProdService.detail(StpKit.USER.getShopId(), id));
    }

    /**
     * pad点餐新增
     *
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "pad布局", value = "padProd:add", name = "pad点餐新增")
    @PostMapping
    public CzgResult<Boolean> add(@RequestBody @Validated PadDetailAddDTO padDetailAddDTO) {
        return CzgResult.success(padProdService.add(StpKit.USER.getShopId(), padDetailAddDTO));
    }

    /**
     * pad点餐修改
     *
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "pad布局", value = "padProd:edit", name = "pad点餐修改")
    @PutMapping
    public CzgResult<Boolean> edit(@RequestBody @Validated PadDetailEditDTO padDetailEditDTO) {
        return CzgResult.success(padProdService.edit(StpKit.USER.getShopId(), padDetailEditDTO));
    }

    /**
     * pad点餐删除
     *
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "pad布局", value = "padProd:del", name = "pad点餐删除")
    @DeleteMapping
    public CzgResult<Boolean> del(@RequestBody @Validated PadDetailDelDTO delDTO) {
        return CzgResult.success(padProdService.del(StpKit.USER.getShopId(), delDTO));
    }
}
