package com.zanxiang.game.module.manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zanxiang.erp.security.annotation.PreAuthorize;
import com.zanxiang.game.module.manage.pojo.params.GameAdPolicyAddOrUpdateParam;
import com.zanxiang.game.module.manage.pojo.params.GameAdPolicyBatchOperationParam;
import com.zanxiang.game.module.manage.pojo.params.GameAdPolicyBatchStartParam;
import com.zanxiang.game.module.manage.pojo.params.GameAdPolicyListParam;
import com.zanxiang.game.module.manage.pojo.vo.GameAdPolicyListVO;
import com.zanxiang.game.module.manage.service.IGameAdMonitorService;
import com.zanxiang.module.util.pojo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tianhua
 * @version 1.0
 * @description: TODO
 * @date 2023/12/28 15:45
 */
@RestController
@RequestMapping("/ad/policy/config")
@Slf4j
public class GameAdMonitorController {

    @Autowired
    private IGameAdMonitorService gameAdMonitorService;

    @PostMapping("/add/or/update")
    @PreAuthorize(permissionKey = "manage:adPolicy:addOrUpdate")
    public ResultVO<Boolean> addOrUpdate(@Validated @RequestBody GameAdPolicyAddOrUpdateParam param) {
        return ResultVO.ok(gameAdMonitorService.addOrUpdate(param));
    }

    @DeleteMapping("/delete/{ids}")
    @PreAuthorize(permissionKey = "manage:adPolicy:delete")
    public ResultVO<Boolean> addOrUpdate(@PathVariable("ids") List<Long> ids) {
        return ResultVO.ok(gameAdMonitorService.deleteByIds(ids));
    }

    @PostMapping("/list")
    @PreAuthorize(permissionKey = "manage:adPolicy:listOfPage")
    public ResultVO<IPage<GameAdPolicyListVO>> listOfPage(@RequestBody GameAdPolicyListParam param) {
        return ResultVO.ok(gameAdMonitorService.listOfPage(param));
    }

    @PostMapping("/batch/operation")
    @PreAuthorize(permissionKey = "manage:adPolicy:batchOperation")
    public ResultVO<Boolean> batchOperation(@Validated @RequestBody GameAdPolicyBatchOperationParam param) {
        return ResultVO.ok(gameAdMonitorService.batchOperation(param));
    }

    @PostMapping("/batch/start")
    @PreAuthorize(permissionKey = "manage:adPolicy:batchStart")
    public ResultVO<Boolean> batchStart(@Validated @RequestBody GameAdPolicyBatchStartParam param) {
        return ResultVO.ok(gameAdMonitorService.batchStart(param));
    }

}
