package com.seer.teach.mall.app.api;

import com.seer.teach.mall.api.MallAfterSaleApi;
import com.seer.teach.mall.api.req.AfterSaleRefundNotifyReq;
import com.seer.teach.mall.service.IAfterSaleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Validated
@Slf4j
@RequiredArgsConstructor
public class MallAfterSaleApiImpl implements MallAfterSaleApi {

    private final IAfterSaleService afterSaleService;

    @Override
    public boolean orderRefundAfterSuccessNotify(AfterSaleRefundNotifyReq afterSaleRefundNotifyReq) {
        log.info("MallAfterSaleApiImpl refund success notify afterSaleSn:{}, afterSaleStatus:{}",
            afterSaleRefundNotifyReq.getAfterSaleSn(), afterSaleRefundNotifyReq.getAfterSaleStatus());
        
        // 处理退款成功通知
        boolean result = afterSaleService.handleRefundSuccessNotify(
            afterSaleRefundNotifyReq.getAfterSaleSn(), 
            afterSaleRefundNotifyReq.getAfterSaleStatus());
        
        log.info("处理退款成功通知结果:{}，售后单号:{}", result, afterSaleRefundNotifyReq.getAfterSaleSn());
        return result;
    }
    
    @Override
    public boolean orderRefundAfterFailNotify(AfterSaleRefundNotifyReq afterSaleRefundNotifyReq) {
        log.info("MallAfterSaleApiImpl refund fail notify afterSaleSn:{}, afterSaleStatus:{}",
            afterSaleRefundNotifyReq.getAfterSaleSn(), afterSaleRefundNotifyReq.getAfterSaleStatus());
        
        // 处理退款失败通知
        boolean result = afterSaleService.handleRefundFailNotify(
            afterSaleRefundNotifyReq.getAfterSaleSn(), 
            afterSaleRefundNotifyReq.getAfterSaleStatus());
        
        log.info("处理退款失败通知结果:{}，售后单号:{}", result, afterSaleRefundNotifyReq.getAfterSaleSn());
        return result;
    }
}