package org.dromara.zhishu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.oss.entity.UploadResult;
import org.dromara.zhishu.util.UploadUtil;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.zhishu.domain.vo.ShopDetailVo;
import org.dromara.zhishu.domain.bo.ShopDetailBo;
import org.dromara.zhishu.service.IShopDetailService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品详情
 *
 * @author yxy
 * @date 2025-03-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhishu/shopDetail")
public class ShopDetailController extends BaseController {

    private final IShopDetailService shopDetailService;

    /**
     * 查询商品详情列表
     */
    @SaCheckPermission("zhishu:shopDetail:list")
    @GetMapping("/list")
    public TableDataInfo<ShopDetailVo> list(ShopDetailBo bo, PageQuery pageQuery) {
        return shopDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商品详情列表
     */
    @SaCheckPermission("zhishu:shopDetail:export")
    @Log(title = "商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ShopDetailBo bo, HttpServletResponse response) {
        List<ShopDetailVo> list = shopDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "商品详情", ShopDetailVo.class, response);
    }

    /**
     * 获取商品详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("zhishu:shop:setUp")
    @GetMapping("/{id}")
    public R<ShopDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(shopDetailService.queryByShopId(id));
    }

    /**
     * 新增商品详情
     */
    @SaCheckPermission("zhishu:shopDetail:add")
    @Log(title = "商品详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ShopDetailBo bo) {
        return toAjax(shopDetailService.insertByBo(bo));
    }

    /**
     * 修改商品详情
     */
    @SaCheckPermission("zhishu:shopDetail:edit")
    @Log(title = "商品详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ShopDetailBo bo) {
        return toAjax(shopDetailService.updateByBo(bo));
    }

    /**
     * 删除商品详情
     *
     * @param ids 主键串
     */
    @SaCheckPermission("zhishu:shopDetail:remove")
    @Log(title = "商品详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(shopDetailService.deleteWithValidByIds(List.of(ids), true));
    }


}
