package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.MemberPriceDto;
import com.mall.coupon.domain.entity.MemberPrice;
import com.mall.coupon.domain.vo.MemberPriceVo;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import com.mall.coupon.service.MemberPriceService;
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 java.util.List;

/**
 * <p>
 * 商品会员价格 前端控制器
 * </p>
 *
 * @author Bunny
 * @since 2025-07-06 11:15:40
 */
@Tag(name = "商品会员价格", description = "商品会员价格相关接口")
@RestController
@RequestMapping("/api/coupon/member-price")
@RequiredArgsConstructor
public class MemberPriceController {

    private final MemberPriceService memberPriceService;

    @Operation(summary = "分页查询商品会员价格", description = "分页商品会员价格")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<MemberPriceVo>> getMemberPricePage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            MemberPriceDto dto) {
        Page<MemberPrice> pageParams = new Page<>(page, limit);
        PageResult<MemberPriceVo> pageResult = memberPriceService.getMemberPricePage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加商品会员价格", description = "添加商品会员价格")
    @PostMapping()
    public Result<String> addMemberPrice(@Valid @RequestBody MemberPriceDto dto) {
            memberPriceService.addMemberPrice(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新商品会员价格", description = "更新商品会员价格")
    @PutMapping()
    public Result<String> updateMemberPrice(@Valid @RequestBody MemberPriceDto dto) {
            memberPriceService.updateMemberPrice(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除商品会员价格", description = "删除商品会员价格")
    @DeleteMapping()
    public Result<String> deleteMemberPrice(@RequestBody List<Long> ids) {
            memberPriceService.deleteMemberPrice(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}