package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.BannerInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.BannerInfoForm;
import com.zsElectric.boot.business.model.query.BannerInfoQuery;
import com.zsElectric.boot.business.model.vo.BannerInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zsElectric.boot.core.web.PageResult;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 小程序banner图前端控制层
 *
 * @author wzq
 * @since 2025-11-26 15:59
 */
@Tag(name = "v2.0 小程序banner图接口")
@RestController
@RequestMapping("/api/v1/bannerInfo")
@RequiredArgsConstructor
public class BannerInfoController  {

    private final BannerInfoService bannerInfoService;

    @Operation(summary = "小程序banner图分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:bannerInfo:query')")
    public PageResult<BannerInfoVO> getBannerInfoPage(BannerInfoQuery queryParams ) {
        IPage<BannerInfoVO> result = bannerInfoService.getBannerInfoPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增小程序banner图")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('business:bannerInfo:add')")
    public Result<Void> saveBannerInfo(@RequestBody @Valid BannerInfoForm formData ) {
        boolean result = bannerInfoService.saveBannerInfo(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取小程序banner图表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:bannerInfo:edit')")
    public Result<BannerInfoForm> getBannerInfoForm(
        @Parameter(description = "小程序banner图ID") @PathVariable Long id
    ) {
        BannerInfoForm formData = bannerInfoService.getBannerInfoFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改小程序banner图")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:bannerInfo:edit')")
    public Result<Void> updateBannerInfo(
            @Parameter(description = "小程序banner图ID") @PathVariable Long id,
            @RequestBody @Validated BannerInfoForm formData
    ) {
        boolean result = bannerInfoService.updateBannerInfo(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除小程序banner图")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('business:bannerInfo:delete')")
    public Result<Void> deleteBannerInfos(
        @Parameter(description = "小程序banner图ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = bannerInfoService.deleteBannerInfos(ids);
        return Result.judge(result);
    }
}
