package com.seer.teach.mall.good.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.common.enums.GoodsAttributeScopeEnum;
import com.seer.teach.mall.good.service.IAdminGoodsAttributeValueService;
import com.seer.teach.mall.request.GoodsAttributeValuePageReq;
import com.seer.teach.mall.request.GoodsAttributeValueReq;
import com.seer.teach.mall.response.GoodsAttributeValueResp;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotEmpty;

import java.util.List;

@RestController
@RequestMapping("/mall/goods/attribute/value")
@Tag(name = "管理端 - 商品属性值管理")
@Validated
@RequiredArgsConstructor
public class AdminGoodsAttributeValueController {

    private final IAdminGoodsAttributeValueService goodsAttributeValueService;

    @PostMapping("/page")
    @LogPrint
    @Operation(summary = "商品属性值分页查询")
    @SaCheckPermission("admin:goods:attribute:value:page")
    public ResultBean<PageListBean<GoodsAttributeValueResp>> getPage(
            @RequestBody @Validated GoodsAttributeValuePageReq pageReq) {
        return ResultBean.success(goodsAttributeValueService.getPage(pageReq));
    }

    @GetMapping("/{id}")
    @LogPrint
    @Operation(summary = "根据ID查询商品属性值")
    @SaCheckPermission("admin:goods:attribute:value:detail")
    public ResultBean<GoodsAttributeValueResp> getById(
            @PathVariable @Parameter(description = "ID") Integer id) {
        return ResultBean.success(goodsAttributeValueService.getById(id));
    }

    @PostMapping
    @LogPrint
    @Operation(summary = "新增商品属性值")
    @SaCheckPermission("admin:goods:attribute:value:save")
    public ResultBean<Boolean> save(
            @RequestBody @Validated GoodsAttributeValueReq req) {
        req.setScope(GoodsAttributeScopeEnum.PLATFORM.getCode());
        return ResultBean.success(goodsAttributeValueService.save(req));
    }

    @PutMapping
    @LogPrint
    @Operation(summary = "修改商品属性值")
    @SaCheckPermission("admin:goods:attribute:value:update")
    public ResultBean<Boolean> update(
            @RequestBody @Validated GoodsAttributeValueReq req) {
        return ResultBean.success(goodsAttributeValueService.update(req));
    }

    @DeleteMapping
    @LogPrint
    @Operation(summary = "删除商品属性值")
    @SaCheckPermission("admin:goods:attribute:value:delete")
    public ResultBean<Boolean> delete(
            @Parameter(description = "ID列表")
            @RequestBody @NotEmpty List<Integer> ids) {
        return ResultBean.success(goodsAttributeValueService.delete(ids));
    }
}