package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.CommonPushTaskNum;
import shop.alien.store.service.CommonPushTaskNumService;

@Api(tags = {"推送任务数量统计管理"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/commonPushTaskNum")
@RequiredArgsConstructor
public class CommonPushTaskNumController {

    private final CommonPushTaskNumService commonPushTaskNumService;

    @ApiOperation("新增推送任务数量统计")
    @ApiOperationSupport(order = 1)
    @PostMapping("/add")
    public R<String> add(@RequestBody CommonPushTaskNum taskNum) {
        return commonPushTaskNumService.add(taskNum);
    }

    @ApiOperation("根据主键删除（逻辑删除）")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "query", required = true)
    })
    @GetMapping("/deleteById")
    public R<String> deleteById(@RequestParam Long id) {
        return commonPushTaskNumService.deleteById(id);
    }

    @ApiOperation("更新推送任务数量统计")
    @ApiOperationSupport(order = 3)
    @PostMapping("/update")
    public R<String> update(@RequestBody CommonPushTaskNum taskNum) {
        return commonPushTaskNumService.update(taskNum);
    }

    @ApiOperation("根据主键查询")
    @ApiOperationSupport(order = 4)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "query", required = true)
    })
    @GetMapping("/getById")
    public R<CommonPushTaskNum> getById(@RequestParam Long id) {
        return commonPushTaskNumService.getInfoById(id);
    }

    @ApiOperation("分页列表")
    @ApiOperationSupport(order = 5)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "pushTaskId", value = "推送任务ID", dataType = "Long", paramType = "query"),
            @ApiImplicitParam(name = "phoneType", value = "机型：1-OPPO 2-VIVO 3-华为 4-苹果 5-荣耀 6-小米 7-三星", dataType = "String", paramType = "query")

    })
    @GetMapping("/list")
    public R<IPage<CommonPushTaskNum>> list(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestParam(required = false) Long pushTaskId,
            @RequestParam(required = false) String phoneType) {
        return commonPushTaskNumService.list(pageNum, pageSize, pushTaskId, phoneType);
    }
}
