package com.usky.cdi.service.sip.push;

import com.usky.cdi.service.sip.config.SipClientProperties;
import com.usky.cdi.service.sip.device.Gb28181DeviceSimulator;
import com.usky.cdi.service.sip.device.Gb28181StreamResult;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * 从 Spring 配置构建 GB28181 推流（委托设备模拟器）。
 */
@Component
@ConditionalOnProperty(prefix = "sip.client", name = "enabled", havingValue = "true")
public class SipVideoPusherFactory {

    private final Gb28181DeviceSimulator deviceSimulator;
    private final SipClientProperties properties;

    public SipVideoPusherFactory(Gb28181DeviceSimulator deviceSimulator, SipClientProperties properties) {
        this.deviceSimulator = deviceSimulator;
        this.properties = properties;
    }

    public Gb28181StreamResult pushRtsp(String rtspUrl, Integer durationSeconds) {
        int duration = durationSeconds != null ? durationSeconds : properties.getDefaultDurationSeconds();
        return deviceSimulator.bindRtspAndWait(rtspUrl, properties.getInviteWaitSeconds(), duration);
    }
}
