package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.CouponSpuRelationDto;
import com.mall.coupon.domain.entity.CouponSpuRelation;
import com.mall.coupon.domain.vo.CouponSpuRelationVo;
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.CouponSpuRelationService;
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/coupon-spu-relation")
@RequiredArgsConstructor
public class CouponSpuRelationController {

    private final CouponSpuRelationService couponSpuRelationService;

    @Operation(summary = "分页查询优惠券与产品关联", description = "分页优惠券与产品关联")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<CouponSpuRelationVo>> getCouponSpuRelationPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            CouponSpuRelationDto dto) {
        Page<CouponSpuRelation> pageParams = new Page<>(page, limit);
        PageResult<CouponSpuRelationVo> pageResult = couponSpuRelationService.getCouponSpuRelationPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加优惠券与产品关联", description = "添加优惠券与产品关联")
    @PostMapping()
    public Result<String> addCouponSpuRelation(@Valid @RequestBody CouponSpuRelationDto dto) {
            couponSpuRelationService.addCouponSpuRelation(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新优惠券与产品关联", description = "更新优惠券与产品关联")
    @PutMapping()
    public Result<String> updateCouponSpuRelation(@Valid @RequestBody CouponSpuRelationDto dto) {
            couponSpuRelationService.updateCouponSpuRelation(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除优惠券与产品关联", description = "删除优惠券与产品关联")
    @DeleteMapping()
    public Result<String> deleteCouponSpuRelation(@RequestBody List<Long> ids) {
            couponSpuRelationService.deleteCouponSpuRelation(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}