package com.erp.tenant.feign;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 通知服务Feign客户端（供tenant-service使用）
 */
@FeignClient(name = "notification-service", url = "${feign.notification-service.url:http://localhost:8087}", fallback = NotificationClientFallback.class)
public interface NotificationFeignClient {

    @PostMapping("/api/notifications/send")
    void sendNotification(@RequestBody NotificationRequest request);

    @PostMapping("/api/notifications/system")
    void sendSystemNotice(@RequestBody SystemNoticeRequest request);

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    class NotificationRequest {
        private String type;
        private String recipient;
        private String title;
        private String content;
        private Long tenantId;
        private String bizType;
        private String bizId;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    class SystemNoticeRequest {
        private Long tenantId;
        private String title;
        private String content;
        private String bizType;
        private String bizId;
    }
}

/**
 * 通知服务降级处理
 */
@Component
class NotificationClientFallback implements NotificationFeignClient {

    @Override
    public void sendNotification(NotificationRequest request) {
        // 降级处理：通知失败不影响主流程
    }

    @Override
    public void sendSystemNotice(SystemNoticeRequest request) {
        // 降级处理
    }
}
