package com.tofly.feesapi.yhgl.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.yhgl.entity.YhFfgx;
import com.tofly.feesapi.yhgl.service.YhFfgxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@RestController
@RequestMapping("api/yhgl/yhffgx")
@Api(tags = "付费关系接口")
public class YhFfgxController {

    @Autowired
    private YhFfgxService yhFfgxService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询", tags = {"付费关系"})
    public ResultRespone getYhFfgxPage(Page page, @ModelAttribute YhFfgx yhFfgx) {
        return ResultRespone.success(yhFfgxService.page(page, Wrappers.query(yhFfgx)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询", tags = {"付费关系"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    public ResultRespone getById(@PathVariable("id") String id) {
        return ResultRespone.success(yhFfgxService.getById(id));
    }

    @ApiOperation(value = "新增付费关系")
    @PostMapping
    public ResultRespone save(@RequestBody YhFfgx yhFfgx) {
        return ResultRespone.success(yhFfgxService.save(yhFfgx));
    }

    @ApiOperation(value = "修改付费关系", tags = {"付费关系"})
    @PutMapping
    public ResultRespone updateById(@RequestBody YhFfgx yhFfgx) {
        return ResultRespone.success(yhFfgxService.updateById(yhFfgx));
    }

    @ApiOperation(value = "通过ID删除付费关系", tags = {"付费关系"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}")
    public ResultRespone removeById(@PathVariable String id) {
        return ResultRespone.success(yhFfgxService.removeById(id));
    }

    @ApiOperation(value = "通过ID批量删除付费关系", tags = {"付费关系"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeByIds(String ids) {
        return ResultRespone.success(yhFfgxService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
