package com.erp.purchase.client;

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

import java.util.List;

/**
 * 仓库服务Feign客户端
 */
@FeignClient(name = "warehouse-service", url = "${warehouse-service.url:}")
public interface WarehouseFeignClient {

    @PostMapping("/api/inbound")
    InboundResponse createInbound(@RequestBody InboundRequest request,
                                  @RequestHeader(value = "X-Operator-Id", required = false) Long operatorId);

    @PostMapping("/api/outbound")
    OutboundResponse createOutbound(@RequestBody OutboundRequest request,
                                    @RequestHeader(value = "X-Operator-Id", required = false) Long operatorId);

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

    class InboundRequest {
        private String relatedNo;
        private String inboundType;
        private Long warehouseId;
        private Long supplierId;
        private String supplierName;
        private String remark;
        private List<InboundItem> items;

        public String getRelatedNo() { return relatedNo; }
        public void setRelatedNo(String relatedNo) { this.relatedNo = relatedNo; }
        public String getInboundType() { return inboundType; }
        public void setInboundType(String inboundType) { this.inboundType = inboundType; }
        public Long getWarehouseId() { return warehouseId; }
        public void setWarehouseId(Long warehouseId) { this.warehouseId = warehouseId; }
        public Long getSupplierId() { return supplierId; }
        public void setSupplierId(Long supplierId) { this.supplierId = supplierId; }
        public String getSupplierName() { return supplierName; }
        public void setSupplierName(String supplierName) { this.supplierName = supplierName; }
        public String getRemark() { return remark; }
        public void setRemark(String remark) { this.remark = remark; }
        public List<InboundItem> getItems() { return items; }
        public void setItems(List<InboundItem> items) { this.items = items; }

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

        public static class Builder {
            private String relatedNo;
            private String inboundType;
            private Long warehouseId;
            private Long supplierId;
            private String supplierName;
            private String remark;
            private List<InboundItem> items;

            public Builder relatedNo(String v) { this.relatedNo = v; return this; }
            public Builder inboundType(String v) { this.inboundType = v; return this; }
            public Builder warehouseId(Long v) { this.warehouseId = v; return this; }
            public Builder supplierId(Long v) { this.supplierId = v; return this; }
            public Builder supplierName(String v) { this.supplierName = v; return this; }
            public Builder remark(String v) { this.remark = v; return this; }
            public Builder items(List<InboundItem> v) { this.items = v; return this; }

            public InboundRequest build() {
                InboundRequest r = new InboundRequest();
                r.relatedNo = this.relatedNo;
                r.inboundType = this.inboundType;
                r.warehouseId = this.warehouseId;
                r.supplierId = this.supplierId;
                r.supplierName = this.supplierName;
                r.remark = this.remark;
                r.items = this.items;
                return r;
            }
        }

        public static class InboundItem {
            private String skuCode;
            private Integer planQuantity;
            private Integer acceptedQuantity;
            private Integer defectiveQuantity;

            public String getSkuCode() { return skuCode; }
            public void setSkuCode(String skuCode) { this.skuCode = skuCode; }
            public Integer getPlanQuantity() { return planQuantity; }
            public void setPlanQuantity(Integer planQuantity) { this.planQuantity = planQuantity; }
            public Integer getAcceptedQuantity() { return acceptedQuantity; }
            public void setAcceptedQuantity(Integer acceptedQuantity) { this.acceptedQuantity = acceptedQuantity; }
            public Integer getDefectiveQuantity() { return defectiveQuantity; }
            public void setDefectiveQuantity(Integer defectiveQuantity) { this.defectiveQuantity = defectiveQuantity; }

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

            public static class Builder {
                private String skuCode;
                private Integer planQuantity;
                private Integer acceptedQuantity;
                private Integer defectiveQuantity;

                public Builder skuCode(String v) { this.skuCode = v; return this; }
                public Builder planQuantity(Integer v) { this.planQuantity = v; return this; }
                public Builder acceptedQuantity(Integer v) { this.acceptedQuantity = v; return this; }
                public Builder defectiveQuantity(Integer v) { this.defectiveQuantity = v; return this; }

                public InboundItem build() {
                    InboundItem i = new InboundItem();
                    i.skuCode = this.skuCode;
                    i.planQuantity = this.planQuantity;
                    i.acceptedQuantity = this.acceptedQuantity;
                    i.defectiveQuantity = this.defectiveQuantity;
                    return i;
                }
            }
        }
    }

    class InboundResponse {
        private String inboundNo;
        private String status;
        private String message;

        public String getInboundNo() { return inboundNo; }
        public void setInboundNo(String inboundNo) { this.inboundNo = inboundNo; }
        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; }
    }

    class OutboundRequest {
        private String relatedNo;
        private String outboundType;
        private Long warehouseId;
        private String remark;
        private List<OutboundItem> items;

        public String getRelatedNo() { return relatedNo; }
        public void setRelatedNo(String relatedNo) { this.relatedNo = relatedNo; }
        public String getOutboundType() { return outboundType; }
        public void setOutboundType(String outboundType) { this.outboundType = outboundType; }
        public Long getWarehouseId() { return warehouseId; }
        public void setWarehouseId(Long warehouseId) { this.warehouseId = warehouseId; }
        public String getRemark() { return remark; }
        public void setRemark(String remark) { this.remark = remark; }
        public List<OutboundItem> getItems() { return items; }
        public void setItems(List<OutboundItem> items) { this.items = items; }

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

        public static class Builder {
            private String relatedNo;
            private String outboundType;
            private Long warehouseId;
            private String remark;
            private List<OutboundItem> items;

            public Builder relatedNo(String v) { this.relatedNo = v; return this; }
            public Builder outboundType(String v) { this.outboundType = v; return this; }
            public Builder warehouseId(Long v) { this.warehouseId = v; return this; }
            public Builder remark(String v) { this.remark = v; return this; }
            public Builder items(List<OutboundItem> v) { this.items = v; return this; }

            public OutboundRequest build() {
                OutboundRequest r = new OutboundRequest();
                r.relatedNo = this.relatedNo;
                r.outboundType = this.outboundType;
                r.warehouseId = this.warehouseId;
                r.remark = this.remark;
                r.items = this.items;
                return r;
            }
        }

        public static class OutboundItem {
            private String skuCode;
            private Integer quantity;

            public String getSkuCode() { return skuCode; }
            public void setSkuCode(String skuCode) { this.skuCode = skuCode; }
            public Integer getQuantity() { return quantity; }
            public void setQuantity(Integer quantity) { this.quantity = quantity; }

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

            public static class Builder {
                private String skuCode;
                private Integer quantity;

                public Builder skuCode(String v) { this.skuCode = v; return this; }
                public Builder quantity(Integer v) { this.quantity = v; return this; }

                public OutboundItem build() {
                    OutboundItem i = new OutboundItem();
                    i.skuCode = this.skuCode;
                    i.quantity = this.quantity;
                    return i;
                }
            }
        }
    }

    class OutboundResponse {
        private String outboundNo;
        private String status;
        private String message;

        public String getOutboundNo() { return outboundNo; }
        public void setOutboundNo(String outboundNo) { this.outboundNo = outboundNo; }
        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; }
    }
}
