package com.example.cezenPBX.entity;

import jakarta.persistence.*;

@Entity
@Table(name = "ps_endpoints")
public class PsEndPoints implements PBXentiry{

    @Id
    @Column(name = "id")
    private String extension;

    @Column(name = "transport")
    private String transport;

    @Column(name = "aors")
    private String aors;

    @Column(name = "auth")
    private String auth;

    @Column(name = "context")
    private String context;

    @Column(name = "disallow")
    private String disallow;

    @Column(name = "allow")
    private String allow;

    @Column(name = "direct_media")
    private String directMedia;

    @Column(name = "connected_line_method")
    private String connectedLineMethod;

    @Column(name = "callerid")
    private String callerid;

    @Column(name = "dtmf_mode")
    private String dtmfMode;

    @Column(name = "mohsuggest")
    private String mohsuggest;

    @Column(name = "mailboxes")
    private String mailboxes;

    public PsEndPoints(String extension, String transport, String aors, String auth, String context,
                       String disallow, String allow, String directMedia, String connectedLineMethod,
                       String callerid, String dtmfMode, String mohsuggest, String mailboxes) {
        this.extension = extension;
        this.transport = transport;
        this.aors = aors;
        this.auth = auth;
        this.context = context;
        this.disallow = disallow;
        this.allow = allow;
        this.directMedia = directMedia;
        this.connectedLineMethod = connectedLineMethod;
        this.callerid = callerid;
        this.dtmfMode = dtmfMode;
        this.mohsuggest = mohsuggest;
        this.mailboxes = mailboxes;
    }

    public PsEndPoints() {
    }

    //This ensures mohsuggest will never be null in the database — it defaults to "default".
    @PrePersist
    @PreUpdate
    public void applyDefaults() {
        if (this.transport == null) {this.transport = "transport-udp";}
        if (this.context == null) this.context = "default";
        if (this.disallow == null) this.disallow = "all";
        if (this.allow == null) this.allow = "ulaw,alaw";
        if (this.directMedia == null) this.directMedia = "no";
        if (this.mohsuggest == null) this.mohsuggest = "default";
    }

    public String getExtension() {
        return extension;
    }

    public String getTransport() {
        return transport;
    }

    public void setTransport(String transport) {
        this.transport = transport;
    }

    public String getAors() {
        return aors;
    }

    public void setAors(String aors) {
        this.aors = aors;
    }

    public String getAuth() {
        return auth;
    }

    public void setAuth(String auth) {
        this.auth = auth;
    }

    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    public String getDisallow() {
        return disallow;
    }

    public void setDisallow(String disallow) {
        this.disallow = disallow;
    }

    public String getAllow() {
        return allow;
    }

    public void setAllow(String allow) {
        this.allow = allow;
    }

    public String getDirectMedia() {
        return directMedia;
    }

    public void setDirectMedia(String directMedia) {
        this.directMedia = directMedia;
    }

    public String getConnectedLineMethod() {
        return connectedLineMethod;
    }

    public void setConnectedLineMethod(String connectedLineMethod) {
        this.connectedLineMethod = connectedLineMethod;
    }

    public String getCallerid() {
        return callerid;
    }

    public void setCallerid(String callerid) {
        this.callerid = callerid;
    }

    public String getDtmfMode() {
        return dtmfMode;
    }

    public void setDtmfMode(String dtmfMode) {
        this.dtmfMode = dtmfMode;
    }

    public String getMohsuggest() {
        return mohsuggest;
    }

    public void setMohsuggest(String mohsuggest) {
        this.mohsuggest = mohsuggest;
    }

    public String getMailboxes() {
        return mailboxes;
    }

    public void setMailboxes(String mailboxes) {
        this.mailboxes = mailboxes;
    }
}
