package SIP;

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

import java.text.MessageFormat;

public class SIP_Response{
    public SIP_Response(SipResponse source) {
        resp = source;
        if (resp!=null) {
            this.statusCode = source.getStatusCode();
            this.reasonPhrase = source.getReasonPhrase();
            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);
            this.Server = common.GetSIPHeaderValue(head, "Server", null);
            this.Date = common.GetSIPHeaderValue(head, "Date", null);
        }
    }
    private @Getter
    final SipResponse resp;

    public int statusCode;
    public String reasonPhrase;
    public String From;
    public String To;
    public String CallID;
    public String Server;
    public String Contact;
    public String Date;

    @Override
    public String toString() {
        return MessageFormat.format("To:{0}\n"
                + "From:{1}\n"
                + "Call-ID:{2}\n"
                + "Contact:{3}\n"
                + "Server:{4}\n"
                + "Date:{5}\n"
                + "StatusCode:{6}\n"
                + "ReasonPhrase:{7}", To, From, CallID, Contact, Server, Date, statusCode, reasonPhrase);
    }
}
