package com.backendsys.modules.b2c.good.controller;

import com.backendsys.modules.b2c.good.entity.Good;
import com.backendsys.modules.b2c.good.entity.GoodCategory;
import com.backendsys.modules.b2c.good.service.GoodCategoryService;
import com.backendsys.modules.b2c.good.service.GoodService;
import com.backendsys.modules.common.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@Tag(name = "商品分类管理")
public class GoodCategoryController {

    @Autowired
    private GoodCategoryService goodCategoryService;

    @Operation(summary = "获取商品分类列表")
    @PreAuthorize("@sr.hasPermission('11.2')")
    @GetMapping("/api/b2c/good/getGoodCategoryList")
    public Result getGoodCategory(@Validated GoodCategory goodCategory) {
        return Result.success().put("data", goodCategoryService.selectGoodCategoryList(goodCategory));
    }

    @Operation(summary = "获取商品分类详情")
    @PreAuthorize("@sr.hasPermission('11.2.1')")
    @GetMapping("/api/b2c/good/getGoodCategoryDetail")
    public Result getGoodCategoryDetail(@Validated(GoodCategory.Detail.class) GoodCategory goodCategory) {
        return Result.success().put("data", goodCategoryService.selectGoodCategoryDetail(goodCategory));
    }

    @Operation(summary = "创建商品分类")
    @PreAuthorize("@sr.hasPermission('11.2.2')")
    @PostMapping("/api/b2c/good/createGoodCategory")
    public Result createGoodCategory(@Validated(GoodCategory.Create.class) @RequestBody GoodCategory goodCategory) {
        return Result.success().put("data", goodCategoryService.insertGoodCategory(goodCategory));
    }

    @Operation(summary = "编辑商品分类")
    @PreAuthorize("@sr.hasPermission('11.2.3')")
    @PutMapping("/api/b2c/good/updateGoodCategory")
    public Result updateGoodCategory(@Validated(GoodCategory.Update.class) @RequestBody GoodCategory goodCategory) {
        return Result.success().put("data", goodCategoryService.updateGoodCategory(goodCategory));
    }

    @Operation(summary = "删除商品分类")
    @PreAuthorize("@sr.hasPermission('11.2.4')")
    @DeleteMapping("/api/b2c/good/deleteGoodCategory")
    public Result deleteGoodCategory(@Validated(GoodCategory.Delete.class) @RequestBody GoodCategory goodCategory) {
        return Result.success().put("data", goodCategoryService.deleteGoodCategory(goodCategory));
    }

}
