package com.tashow.cloud.product.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.productapi.api.product.dto.CategoryDO;
import com.tashow.cloud.product.service.CategoryService;
import com.tashow.cloud.productapi.api.product.dto.CategoryDto;
import com.tashow.cloud.productapi.api.product.vo.CategorySaveReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.tashow.cloud.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 产品类目")
@RestController
@RequestMapping("/product/category")
@Validated
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * 获取菜单页面的表
     * @return
     */
    @PermitAll
    @GetMapping("/categoryList")
    public CommonResult<List<CategoryDO>> categoryList(@RequestParam(value = "grade", required = false) Integer grade,
                                                        @RequestParam(value = "categoryId", required = false) Long categoryId,
                                                        @RequestParam(value = "categoryName", required = false) String categoryName,
                                                        @RequestParam(value = "status", required = false) Integer status) {
        return success(categoryService.categoryList(grade, categoryId,categoryName, status));
    }
    @PostMapping("/create")
    @Operation(summary = "创建产品类目")
    @PermitAll
    public CommonResult<Long> createCategory(@Valid @RequestBody CategorySaveReqVO createReqVO) {
        return success(categoryService.createCategory(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新产品类目")
    @PermitAll
    public CommonResult<Boolean> updateCategory(@RequestBody CategorySaveReqVO updateReqVO) {
        categoryService.updateCategory(updateReqVO);
        return success(true);
    }
/*
    @DeleteMapping("/delete")
    @Operation(summary = "删除产品类目")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('tz:category:delete')")
    public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) {
        categoryService.deleteCategory(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得产品类目")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('tz:category:query')")
    public CommonResult<CategoryRespVO> getCategory(@RequestParam("id") Long id) {
        CategoryDO category = categoryService.getCategory(id);
        return success(BeanUtils.toBean(category, CategoryRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得产品类目分页")
    @PreAuthorize("@ss.hasPermission('tz:category:query')")
    public CommonResult<PageResult<CategoryRespVO>> getCategoryPage(@Valid CategoryPageReqVO pageReqVO) {
        PageResult<CategoryDO> pageResult = categoryService.getCategoryPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, CategoryRespVO.class));
    }*/

/*    @GetMapping("/export-excel")
    @Operation(summary = "导出产品类目 Excel")
    @PreAuthorize("@ss.hasPermission('tz:category:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportCategoryExcel(@Valid CategoryPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<CategoryDO> list = categoryService.getCategoryPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "产品类目.xls", "数据", CategoryRespVO.class,
                        BeanUtils.toBean(list, CategoryRespVO.class));
    }*/

}