package cn.skcks.docking.gb28181.wvp.config;

import cn.skcks.docking.gb28181.config.sip.SipConfig;
import cn.skcks.docking.gb28181.sdp.media.MediaStreamMode;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.sip.ListeningPoint;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Component
@ConfigurationProperties(prefix = "proxy.gb28181.sip", ignoreInvalidFields = true)
@Order(0)
@Data
public class ProxySipConfig {
    private List<String> ip;

    private List<String> showIp;

    private Integer port;

    private String domain;

    private String id;

    private String password;

    private String transport = ListeningPoint.UDP;

    private MediaStreamMode streamMode = MediaStreamMode.TCP_PASSIVE;

    /**
     * 某些特殊情况下 使用 视频回放点播 代替 下载
     */
    private boolean usePlaybackToDownload = false;

    /**
     * 代理 zlm 地址, 用于 /video/device/video.mp4 替换返回值地址
     * <p>例: http://127.0.0.1:5080</p>
     */
    private String proxyMediaUrl = "";

    /**
     * 调用 视频下载之前 是否使用 recordInfo 查询
     */
    private boolean useRecordInfoQueryBeforeDownload = true;
    private int retryRecordInfoQueryBeforeDownloadTimes = 20;
    private long retryRecordInfoQueryBeforeDownloadInterval = 3;
    private TimeUnit retryRecordInfoQueryBeforeDownloadIntervalUnit = TimeUnit.SECONDS;

    @Bean
    public SipConfig sipConfig(){
        SipConfig sipConfig = new SipConfig();
        sipConfig.setIp(ip);
        sipConfig.setShowIp(showIp);
        sipConfig.setPort(port);
        sipConfig.setDomain(domain);
        sipConfig.setId(id);
        sipConfig.setPassword(password);
        return sipConfig;

    }
}
