package com.org.hktshop.controller.user;

import com.org.hktshop.base.BaseResult;
import com.org.hktshop.entity.user.HktUsersInvoice;
import com.org.hktshop.service.user.HktUsersInvoiceService;
import com.org.hktshop.utils.HttpCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/async/userInvoice")
@Api(tags = "管理端用户发票接口")
public class HktUserInvoiceAdminController {
    @Autowired
    private HktUsersInvoiceService usersInvoiceService;

    @GetMapping("/getUserInvoiceByUserId")
    @ApiOperation(value = "userId查询用户发票信息", notes = "userId查询用户发票信息")
    public BaseResult<HktUsersInvoice> getOrderInvoiceById(@RequestParam("userId") String userId) {
        try {
            HktUsersInvoice HktUsersInvoice = usersInvoiceService.getHktUsersInvoiceByUserId(userId);
            return BaseResult.successWithData(HktUsersInvoice);
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @PostMapping("/updateUserInvoice")
    @ApiOperation(value = "更新个人发票", notes = "更新个人发票")
    public BaseResult updateUserInvoice(@RequestBody HktUsersInvoice hktUsersInvoice) {
        try {
            usersInvoiceService.updateHktUsersInvoice(hktUsersInvoice);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }
}
