package com.sqx.modules.invoice.controller.app;

import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.invoice.entity.Invoice;
import com.sqx.modules.invoice.service.InvoiceService;
import com.sqx.modules.orders.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@Api(value = "发票管理", tags = {"用户端-发票管理"})
@RequestMapping(value = "/app/invoice/")
public class AppInvoiceController {

    @Autowired
    private InvoiceService invoiceService;
    @Autowired
    private OrdersService ordersService;

    @Login
    @ApiOperation("用户获取可申请发票的订单列表")
    @GetMapping("getIndentList")
    public Result getIndentList(Integer page, Integer limit, @RequestAttribute("userId") Long userId, String ordersNo, String startTime, String endTime) {
        return Result.success().put("data", ordersService.selectOrdersListByInvoice(page, limit, userId, ordersNo, startTime, endTime));
    }

    @Login
    @ApiOperation("用户申请发票")
    @PostMapping("applyInvoice")
    public Result applyInvoice(@RequestAttribute("userId") Long userId, @RequestBody Invoice invoice) {
        return invoiceService.applyInvoice(userId, invoice);
    }

    @Login
    @ApiOperation("用户获取发票信息")
    @GetMapping("getInvoiceInfo")
    public Result getInvoiceInfo(Long invoiceId, String indentNumber) {
        return Result.success().put("data", invoiceService.getInvoiceInfo(invoiceId, indentNumber));
    }

    @Login
    @ApiOperation("获取开票记录")
    @GetMapping("getMyInvoiceList")
    public Result getMyInvoiceList(Integer page,Integer limit ,@RequestAttribute("userId")Long userId){
        return Result.success().put("data", invoiceService.getMyInvoiceList(page,limit,userId));
    }
}
