package com.fdkankan.platform.user.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.platform.order.service.IInvoiceService;
import com.fdkankan.platform.user.request.RequestInvoice;
import com.fdkankan.platform.user.vo.ResponseInvoice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 个人中心-增值发票
 */
@RestController
@RequestMapping("/service/platform/user/invoice")
public class UserInvoiceController {

    private static Logger log = LoggerFactory.getLogger("programLog");

    @Autowired
    private IInvoiceService invoiceService;


    /**
     * 获得可开发票的最高额度
     * cameraId     设备id
     * @return
     */
    @RequestMapping(value = "/max", method = RequestMethod.POST)
    public Integer getMaxInvoice(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.getMaxInvoice(param,token);
    }

    /**
     * 获取用户发票记录
     * cameraId       相机id
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Page<ResponseInvoice> list(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.listInvoice(param,token);
    }

    /**
     * 获取用户发票记录
     * invoiceType      发票类型，2表示增值税普通发票，3表示增值税专用发票
     * @return
     */
    @RequestMapping(value = "/mine", method = RequestMethod.POST)
    public ResponseInvoice mine(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.mineInvoice(param,token);
    }

    /**
     * 保存用户发票信息
     * cameraId          相机id
     * invoiceType          发票类型，2表示增值税普通发票，3表示增值税专用发票
     * title          发票抬头
     * code          税号
     * organizedAddress          公司地址
     * registerPhone          注册电话
     * bankName          开户银行
     * bankAccount          银行账户
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.saveInvoice(param,token);
    }

    /**
     * 获取发票详情
     * invoiceId          发票id
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    public ResponseInvoice detail(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.detailInvoice(param,token);
    }

    /**
     * 申请开票
     * invoiceType          发票类型，2表示增值税普通发票，3表示增值税专用发票
     * title          发票抬头
     * code          税号
     * amount           开票金额
     * organizedAddress          公司地址
     * registerPhone          注册电话
     * bankName          开户银行
     * bankAccount          银行账户
     * shipName         收货人姓名
     * shipAreaPath     收货地区路径
     * shipAddress      收货地址
     * shipMobile       收货手机
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.addInvoice(param,token);
    }

    /**
     * 修改开票信息
     * invoiceType          发票类型，2表示增值税普通发票，3表示增值税专用发票
     * title          发票抬头
     * code          税号
     * amount           开票金额
     * organizedAddress          公司地址
     * registerPhone          注册电话
     * bankName          开户银行
     * bankAccount          银行账户
     * shipName         收货人姓名
     * shipAreaPath     收货地区路径
     * shipAddress      收货地址
     * shipMobile       收货手机
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.updateInvoice(param,token);
    }

    /**
     * 不开发票
     * invoiceId       发票id
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String deleteInvoice(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.deleteInvoice(param,token);
    }


    /**
     * 申请开票
     * consumeType         0表示购买相机，1消费订单，2会员权益 , 3下载订单
     * orderId              订单Id
     * type             发票类型，2表示增值税普通发票，3表示增值税专用发票
     * title          发票抬头
     * code          税号
     * amount           开票金额
     * organizedAddress          公司地址
     * registerPhone          注册电话
     * bankName          开户银行
     * bankAccount          银行账户
     * shipName         收货人姓名
     * shipAreaPath     收货地区路径
     * shipAddress      收货地址
     * shipMobile       收货手机
     * @return
     */
    @RequestMapping(value = "/open", method = RequestMethod.POST)
    public ResponseInvoice open(@RequestBody RequestInvoice param, @RequestHeader String token) throws Exception {
        return invoiceService.openInvoice(param,token);
    }

}
