package com.czg.controller.admin;

import com.czg.market.dto.SmsPushEventDTO;
import com.czg.market.service.SmsPushEventService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 短信推送任务
 *
 * @author ww
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/admin/pushEvent")
public class SmsPushEventController {
    @Resource
    private SmsPushEventService pushEventService;

    /**
     * 列表
     */
    @GetMapping
    public CzgResult<Page<SmsPushEventDTO>> getPushEventPage(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                             @RequestParam(required = false, defaultValue = "10") Integer size,
                                                             @RequestParam(required = false) Integer status,
                                                             @RequestParam(required = false) Long id) {
        Page<SmsPushEventDTO> data = pushEventService.getPushEventPage(page, size, StpKit.USER.getShopId(), status, id);
        return CzgResult.success(data);
    }

    /**
     * 新增
     */
    @PostMapping
    public CzgResult<Void> addPushEvent(@RequestBody @Validated(InsertGroup.class) SmsPushEventDTO param) {
        param.setShopId(StpKit.USER.getShopId());
        pushEventService.addPushEvent(param);
        return CzgResult.success();
    }

    /**
     * 更新
     */
    @PutMapping
    public CzgResult<Void> upPushEvent(@RequestBody @Validated(UpdateGroup.class) SmsPushEventDTO param) {
        param.setShopId(StpKit.USER.getShopId());
        pushEventService.upPushEvent(param);
        return CzgResult.success();
    }

    /**
     * 删除任务
     */
    @DeleteMapping("/{id}")
    public CzgResult<Void> deletePushEvent(@PathVariable Long id) {
        pushEventService.deletePushEvent(id);
        return CzgResult.success();
    }
}
