package com.playlet.web.controller.app;

import com.github.pagehelper.PageInfo;
import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PlayletUserInvoice;
import com.playlet.web.service.app.PlayletUserInvoiceAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date: 2024-03-25 15:50
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 用户开票信息app Controller
 */
@Controller
@RequestMapping("/app/invoice")
@Api(tags = "小程序*开票信息接口")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletUserInvoiceAppController {

    private final PlayletUserInvoiceAppService playletUserInvoiceAppService;

    /**
     * 查询用户开票信息基础列表
     */
    @ResponseBody
    @PostMapping("/getInvoiceList")
    @ApiOperation(value = "分页查询开票信息")
    public Result<PageInfo<PlayletUserInvoice>> getInvoiceList(@RequestBody PlayletUserInvoice invoice,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return Result.success(playletUserInvoiceAppService.getInvoiceList(invoice, pageNum, pageSize));
    }

    /**
     * 查询用户开票信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询开票信息列表")
    public Result<List<PlayletUserInvoice>> list(@RequestBody PlayletUserInvoice playletUserInvoice) {
        return Result.success(playletUserInvoiceAppService.selectPlayletUserInvoiceList(playletUserInvoice));
    }


    /**
     * 新增保存用户开票信息
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "新增开票信息")
    public Result<String> addSave(@RequestBody PlayletUserInvoice playletUserInvoice) {
        playletUserInvoiceAppService.insertPlayletUserInvoice(playletUserInvoice);
        return Result.success();
    }

    /**
     * 修改保存用户开票信息
     */
    @ResponseBody
    @PostMapping("/edit")
    @ApiOperation(value = "修改开票信息")
    public Result<String> editSave(@RequestBody PlayletUserInvoice playletUserInvoice) {
        playletUserInvoiceAppService.updatePlayletUserInvoice(playletUserInvoice);
        return Result.success();
    }

    /**
     * 删除用户开票信息
     */
    @PostMapping("/remove")
    @ResponseBody
    @ApiOperation(value = "删除开票信息")
    public Result<String> remove(@RequestParam(value = "id") Long id) {
        playletUserInvoiceAppService.deletePlayletUserInvoiceById(id);
        return Result.success();
    }
}

