package com.xunhong.erp.turbo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.SupplierInvoiceServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.SupplierInvoiceCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.SupplierInvoiceDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.SupplierInvoiceUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.SupplierInvoiceListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.SupplierInvoicePageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.SupplierInvoiceShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.SupplierInvoiceVO;
import com.xunhong.erp.turbo.base.dto.PageDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenyifei
 */
@Tag(name = "SupplierInvoice", description = "瓜农发票管理")
@RestController("operationSupplierInvoiceController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class SupplierInvoiceController {

	@DubboReference(version = "1.0.0")
	private final SupplierInvoiceServiceI supplierInvoiceService;

	@SaCheckLogin
	@GetMapping("listSupplierInvoice")
	@Operation(summary = "瓜农发票列表", method = "GET")
	public MultiResponse<SupplierInvoiceVO> listSupplierInvoice(@ModelAttribute @Validated SupplierInvoiceListQry supplierInvoiceListQry) {
		return MultiResponse.of(supplierInvoiceService.list(supplierInvoiceListQry));
	}

	@SaCheckLogin
	@PostMapping("createSupplierInvoice")
	@Operation(summary = "创建发票", method = "POST")
	public SingleResponse<SupplierInvoiceVO> createSupplierInvoice(@RequestBody @Validated SupplierInvoiceCreateCmd supplierInvoiceCreateCmd) {
		return SingleResponse.of(supplierInvoiceService.create(supplierInvoiceCreateCmd));
	}

	@SaCheckLogin
	@GetMapping("showSupplierInvoice")
	@Operation(summary = "瓜农发票详情", method = "GET")
	public SingleResponse<SupplierInvoiceVO> showSupplierInvoice(@ModelAttribute @Validated SupplierInvoiceShowQry supplierInvoiceShowQry) {
		return SingleResponse.of(supplierInvoiceService.show(supplierInvoiceShowQry));
	}

	@SaCheckLogin
	@GetMapping("pageSupplierInvoice")
	@Operation(summary = "瓜农发票列表", method = "GET")
	public PageResponse<SupplierInvoiceVO> pageSupplierInvoice(@ModelAttribute @Validated SupplierInvoicePageQry supplierInvoicePageQry) {
		PageDTO<SupplierInvoiceVO> page = supplierInvoiceService.page(supplierInvoicePageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
	@RequestMapping(value = "updateSupplierInvoice", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "瓜农发票更新", method = "PATCH")
	public SingleResponse<SupplierInvoiceVO> updateSupplierInvoice(@RequestBody @Validated SupplierInvoiceUpdateCmd invoiceUpdateCmd) {
		return SingleResponse.of(supplierInvoiceService.update(invoiceUpdateCmd));
	}

	@SaCheckLogin
	@DeleteMapping("destroySupplierInvoice")
	@Operation(summary = "瓜农发票删除", method = "DELETE")
	public Response destroySupplierInvoice(@RequestBody @Validated SupplierInvoiceDestroyCmd supplierInvoiceDestroyCmd) {
		supplierInvoiceService.destroy(supplierInvoiceDestroyCmd);
		return Response.buildSuccess();
	}
}
