package com.pig4cloud.pig.marketing.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.marketing.api.dto.app.ModMarketingAppsIpDTO;
import com.pig4cloud.pig.marketing.api.dto.rule.PageMktRuleDTO;
import com.pig4cloud.pig.marketing.api.dto.rule.SaveMktRuleDTO;
import com.pig4cloud.pig.marketing.api.vo.rule.PageMktRuleVO;
import com.pig4cloud.pig.marketing.service.MktMgmtRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: lwh
 * @date: 2025-08-31
 * @description: 营销管理规则
 */
@RestController
@AllArgsConstructor
@RequestMapping("/rule")
@Tag(description = "marketingRule", name = "营销规则")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class MktMgmtRuleController {

	private final MktMgmtRuleService mktMgmtRuleService;


	@PostMapping("/save")
	@Operation(summary = "新增/修改营销规则")
	public R<String> saveRule(@Valid @RequestBody SaveMktRuleDTO reqDto) {
		mktMgmtRuleService.saveMktRule(reqDto);
		return R.ok();
	}

	@GetMapping("/del")
	@Operation(summary = "删除营销规则")
	public R<Boolean> delRule(@Valid @NotEmpty(message = "id列表不能为空") @RequestParam List<Long> ids) {
		return R.ok(mktMgmtRuleService.delMktRuleByIds(ids));
	}

	@PostMapping("/page")
	@Operation(summary = "分页查询营销规则")
	public R<Page<PageMktRuleVO>> pageRule(@Valid @RequestBody PageMktRuleDTO reqDto) {
		Page<PageMktRuleVO> result = mktMgmtRuleService.pageMktRule(reqDto);
		return R.ok(result);
	}

	@GetMapping("/get")
	@Operation(summary = "查询营销规则详情")
	public R<PageMktRuleVO> pageRule(@NotNull(message = "id不能为空") @ParameterObject Long id) {
		PageMktRuleVO result = mktMgmtRuleService.getMktRuleById(id);
		return R.ok(result);
	}
}
