package com.erp.purchase.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 财务服务Feign客户端
 */
@FeignClient(name = "finance-service", url = "${finance-service.url:}")
public interface FinanceFeignClient {

    @PostMapping("/api/finance/ap/create")
    AccountsPayableResponse createAccountsPayable(@RequestBody AccountsPayableRequest request);

    @PutMapping("/api/finance/ap/{purchaseOrderNo}/cancel")
    void cancelAccountsPayable(@PathVariable String purchaseOrderNo);

    @PutMapping("/api/finance/ap/{purchaseOrderNo}/inbound")
    void updateInboundStatus(@PathVariable String purchaseOrderNo,
                             @RequestParam String inboundNo,
                             @RequestParam BigDecimal inboundAmount,
                             @RequestParam String action);

    @PostMapping("/api/finance/refund")
    void processRefund(@RequestParam String purchaseOrderNo,
                       @RequestParam String returnNo,
                       @RequestParam BigDecimal refundAmount);

    // ---- 数据结构 ----

    class AccountsPayableRequest {
        private Long purchaseOrderId;
        private String purchaseOrderNo;
        private Long supplierId;
        private BigDecimal amount;
        private String paymentMethod;

        public Long getPurchaseOrderId() { return purchaseOrderId; }
        public void setPurchaseOrderId(Long purchaseOrderId) { this.purchaseOrderId = purchaseOrderId; }
        public String getPurchaseOrderNo() { return purchaseOrderNo; }
        public void setPurchaseOrderNo(String purchaseOrderNo) { this.purchaseOrderNo = purchaseOrderNo; }
        public Long getSupplierId() { return supplierId; }
        public void setSupplierId(Long supplierId) { this.supplierId = supplierId; }
        public BigDecimal getAmount() { return amount; }
        public void setAmount(BigDecimal amount) { this.amount = amount; }
        public String getPaymentMethod() { return paymentMethod; }
        public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; }

        public static Builder builder() { return new Builder(); }

        public static class Builder {
            private Long purchaseOrderId;
            private String purchaseOrderNo;
            private Long supplierId;
            private BigDecimal amount;
            private String paymentMethod;

            public Builder purchaseOrderId(Long v) { this.purchaseOrderId = v; return this; }
            public Builder purchaseOrderNo(String v) { this.purchaseOrderNo = v; return this; }
            public Builder supplierId(Long v) { this.supplierId = v; return this; }
            public Builder amount(BigDecimal v) { this.amount = v; return this; }
            public Builder paymentMethod(String v) { this.paymentMethod = v; return this; }

            public AccountsPayableRequest build() {
                AccountsPayableRequest r = new AccountsPayableRequest();
                r.purchaseOrderId = this.purchaseOrderId;
                r.purchaseOrderNo = this.purchaseOrderNo;
                r.supplierId = this.supplierId;
                r.amount = this.amount;
                r.paymentMethod = this.paymentMethod;
                return r;
            }
        }
    }

    class AccountsPayableResponse {
        private String apNo;
        private String status;
        private String message;

        public String getApNo() { return apNo; }
        public void setApNo(String apNo) { this.apNo = apNo; }
        public String getStatus() { return status; }
        public void setStatus(String status) { this.status = status; }
        public String getMessage() { return message; }
        public void setMessage(String message) { this.message = message; }
    }
}
