package com.org.hktshop.controller.user;

import com.org.hktshop.base.BaseResult;
import com.org.hktshop.controller.HktBaseController;
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.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/shop/userInvoice")
@Api(tags = "个人发票接口")
public class HktUsersInvoiceController extends HktBaseController {

    @Autowired
    private HktUsersInvoiceService usersInvoice;

    @PostMapping("/saveUserInvoice")
    @ApiOperation(value = "新增个人发票", notes = "新增个人发票")
    public BaseResult saveUserInvoice(@RequestBody HktUsersInvoice hktUsersInvoice) {
        try {
            hktUsersInvoice.setUserId(userInfo.getId());
            usersInvoice.saveHktUsersInvoice(hktUsersInvoice);
            return BaseResult.success();
        } 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 {
            hktUsersInvoice.setUserId(userInfo.getId());
            usersInvoice.updateHktUsersInvoice(hktUsersInvoice);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @GetMapping("/deleteUserInvoice")
    @ApiOperation(value = "通过id删除个人发票信息", notes = "通过id删除个人发票信息")
    @ApiImplicitParam(name = "id", value = "主键id", required = true, paramType = "query")
    public BaseResult deleteUserInvoice(@RequestParam("id") String id) {
        try {
            HktUsersInvoice hktUsersInvoice = new HktUsersInvoice();
            hktUsersInvoice.setUserId(userInfo.getId());
            hktUsersInvoice.setId(id);
            usersInvoice.deleteHktUsersInvoice(hktUsersInvoice);
            return BaseResult.success();
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }

    @GetMapping("/getUserInvoice")
    @ApiOperation(value = "获取个人发票信息", notes = "获取个人发票信息")
    public BaseResult getUserInvoice() {
        try {
            HktUsersInvoice hktUsersInvoice = usersInvoice.getHktUsersInvoice();
            return BaseResult.successWithData(hktUsersInvoice);
        } catch (Exception ex) {
            return BaseResult.fail(HttpCode.INTERNAL_SERVER_ERROR.getCode(), HttpCode.INTERNAL_SERVER_ERROR.getMsg());
        }
    }
}
