package com.mall.coupon.controller;

import com.mall.coupon.domain.dto.HomeAdvDto;
import com.mall.coupon.domain.entity.HomeAdv;
import com.mall.coupon.domain.vo.HomeAdvVo;
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.HomeAdvService;
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-adv")
@RequiredArgsConstructor
public class HomeAdvController {

    private final HomeAdvService homeAdvService;

    @Operation(summary = "分页查询首页轮播广告", description = "分页首页轮播广告")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<HomeAdvVo>> getHomeAdvPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            HomeAdvDto dto) {
        Page<HomeAdv> pageParams = new Page<>(page, limit);
        PageResult<HomeAdvVo> pageResult = homeAdvService.getHomeAdvPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "添加首页轮播广告", description = "添加首页轮播广告")
    @PostMapping()
    public Result<String> addHomeAdv(@Valid @RequestBody HomeAdvDto dto) {
            homeAdvService.addHomeAdv(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新首页轮播广告", description = "更新首页轮播广告")
    @PutMapping()
    public Result<String> updateHomeAdv(@Valid @RequestBody HomeAdvDto dto) {
            homeAdvService.updateHomeAdv(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除首页轮播广告", description = "删除首页轮播广告")
    @DeleteMapping()
    public Result<String> deleteHomeAdv(@RequestBody List<Long> ids) {
            homeAdvService.deleteHomeAdv(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}