package com.erp.supplier.client;

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

/**
 * 采购服务Feign客户端
 * 用于与采购模块联动，当询价单确认时通知采购模块创建采购单
 */
@FeignClient(name = "purchase-service", url = "${purchase.service.url:http://purchase-service}")
public interface PurchaseClient {

    /**
     * 根据询价单创建采购单
     */
    @PostMapping("/api/purchases/create-from-inquiry")
    ApiResult<Long> createPurchaseFromInquiry(@RequestBody PurchaseFromInquiryRequest request);

    /**
     * 获取采购单状态
     */
    @GetMapping("/api/purchases/{id}/status")
    ApiResult<String> getPurchaseStatus(@PathVariable("id") Long id);

    @Data
    class PurchaseFromInquiryRequest {
        private Long inquiryId;
        private String inquiryNo;
        private Long supplierId;
        private String supplierName;
        private Long productId;
        private String productName;
        private String productSpec;
        private String unit;
        private java.math.BigDecimal quantity;
        private java.math.BigDecimal quotedPrice;
        private String currency;
        private Integer deliveryCycle;
        private String qualityStandard;
        private String paymentTerms;
        private String expectedDeliveryDate;
        private String remark;
        private Long creatorId;
        private String creatorName;
    }

    @Data
    class ApiResult<T> {
        private int code;
        private T data;
        private String message;

        public static <T> ApiResult<T> success(T data) {
            ApiResult<T> result = new ApiResult<>();
            result.setCode(200);
            result.setData(data);
            result.setMessage("success");
            return result;
        }

        public static <T> ApiResult<T> error(int code, String message) {
            ApiResult<T> result = new ApiResult<>();
            result.setCode(code);
            result.setMessage(message);
            return result;
        }
    }
}
