package SIP;

import code.common;
import lombok.Getter;
import peers.sip.syntaxencoding.SipHeaders;
import peers.sip.transport.SipRequest;

import java.text.MessageFormat;

public class SIP_Request{
    private @Getter
    final SipRequest req;
    public String To;
    public String From;
    public String CallID;
    public String Contact;


    public SIP_Request(SipRequest source) {
        req = source;
        if (req!=null) {
            SipHeaders head = source.getSipHeaders();
            this.To = common.GetSIPHeaderValue(head,"To", null);
            this.From = common.GetSIPHeaderValue(head, "From", null);
            this.CallID = common.GetSIPHeaderValue(head, "Call-ID", null);
            this.Contact = common.GetSIPHeaderValue(head, "Contact", null);
        }
    }

    @Override
    public String toString() {
        return MessageFormat.format("To:{0}\n"
                + "From:{1}\n"
                + "Call-ID:{2}\n"
                + "Contact:{3}", To, From, CallID, Contact);
    }
}
