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.AttrAttrgroupRelationDto;
import com.mall.product.domain.entity.AttrAttrgroupRelation;
import com.mall.product.domain.vo.AttrAttrgroupRelationVo;
import com.mall.product.service.AttrAttrgroupRelationService;
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/attrAttrgroupRelation")
@RequiredArgsConstructor
public class AttrAttrgroupRelationController {

    private final AttrAttrgroupRelationService attrAttrgroupRelationService;

    @Operation(summary = "分页查询属性&属性分组关联", description = "分页属性&属性分组关联")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<AttrAttrgroupRelationVo>> getAttrAttrgroupRelationPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            AttrAttrgroupRelationDto dto) {
        Page<AttrAttrgroupRelation> pageParams = new Page<>(page, limit);
        PageResult<AttrAttrgroupRelationVo> pageResult = attrAttrgroupRelationService.getAttrAttrgroupRelationPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加属性&属性分组关联", description = "添加属性&属性分组关联")
    @PostMapping()
    public Result<String> addAttrAttrgroupRelation(@Valid @RequestBody AttrAttrgroupRelationDto dto) {
        attrAttrgroupRelationService.addAttrAttrgroupRelation(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新属性&属性分组关联", description = "更新属性&属性分组关联")
    @PutMapping()
    public Result<String> updateAttrAttrgroupRelation(@Valid @RequestBody AttrAttrgroupRelationDto dto) {
        attrAttrgroupRelationService.updateAttrAttrgroupRelation(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

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