package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.HomeSubjectSpuDto;
import com.mall.coupon.domain.entity.HomeSubjectSpu;
import com.mall.coupon.domain.vo.HomeSubjectSpuVo;
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.HomeSubjectSpuService;
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/home-subject-spu")
@RequiredArgsConstructor
public class HomeSubjectSpuController {

    private final HomeSubjectSpuService homeSubjectSpuService;

    @Operation(summary = "分页查询专题商品", description = "分页专题商品")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<HomeSubjectSpuVo>> getHomeSubjectSpuPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            HomeSubjectSpuDto dto) {
        Page<HomeSubjectSpu> pageParams = new Page<>(page, limit);
        PageResult<HomeSubjectSpuVo> pageResult = homeSubjectSpuService.getHomeSubjectSpuPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加专题商品", description = "添加专题商品")
    @PostMapping()
    public Result<String> addHomeSubjectSpu(@Valid @RequestBody HomeSubjectSpuDto dto) {
            homeSubjectSpuService.addHomeSubjectSpu(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新专题商品", description = "更新专题商品")
    @PutMapping()
    public Result<String> updateHomeSubjectSpu(@Valid @RequestBody HomeSubjectSpuDto dto) {
            homeSubjectSpuService.updateHomeSubjectSpu(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除专题商品", description = "删除专题商品")
    @DeleteMapping()
    public Result<String> deleteHomeSubjectSpu(@RequestBody List<Long> ids) {
            homeSubjectSpuService.deleteHomeSubjectSpu(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}