package com.mall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;
import com.mall.product.domain.dto.AttrGroupDto;
import com.mall.product.domain.entity.AttrGroup;
import com.mall.product.domain.vo.AttrGroupVo;
import com.mall.product.service.AttrGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 15:19:19
 */
@Tag(name = "属性分组", description = "属性分组相关接口")
@RestController
@RequestMapping("/api/product/attrGroup")
@RequiredArgsConstructor
public class AttrGroupController {

    private final AttrGroupService attrGroupService;

    @Operation(summary = "分页查询属性分组", description = "分页属性分组")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<AttrGroupVo>> getAttrGroupPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            AttrGroupDto dto) {
        Page<AttrGroup> pageParams = new Page<>(page, limit);
        PageResult<AttrGroupVo> pageResult = attrGroupService.getAttrGroupPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加属性分组", description = "添加属性分组")
    @PostMapping()
    public Result<String> addAttrGroup(@Valid @RequestBody AttrGroupDto dto) {
        attrGroupService.addAttrGroup(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新属性分组", description = "更新属性分组")
    @PutMapping()
    public Result<String> updateAttrGroup(@Valid @RequestBody AttrGroupDto dto) {
        attrGroupService.updateAttrGroup(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除属性分组", description = "删除属性分组")
    @DeleteMapping()
    public Result<String> deleteAttrGroup(@RequestBody List<Long> ids) {
        attrGroupService.deleteAttrGroup(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}