001// --------------------------------------------------------------------------------
002// Copyright 2002-2026 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.model.control.contact.server.graphql;
018
019import com.echothree.model.control.contact.common.workflow.TelephoneStatusConstants;
020import com.echothree.model.control.geo.server.graphql.GeoCodeObject;
021import com.echothree.model.control.geo.server.graphql.GeoSecurityUtils;
022import com.echothree.model.control.graphql.server.graphql.BaseObject;
023import com.echothree.model.control.workflow.server.graphql.WorkflowEntityStatusObject;
024import com.echothree.model.data.contact.server.entity.ContactTelephone;
025import com.echothree.util.common.persistence.BasePK;
026import graphql.annotations.annotationTypes.GraphQLDescription;
027import graphql.annotations.annotationTypes.GraphQLField;
028import graphql.annotations.annotationTypes.GraphQLName;
029import graphql.schema.DataFetchingEnvironment;
030
031@GraphQLDescription("contact telephone object")
032@GraphQLName("ContactTelephone")
033public class ContactTelephoneObject
034        extends BaseObject
035        implements ContactMechanismInterface {
036
037    private final BasePK basePrimaryKey; // Always Present
038    private final ContactTelephone contactTelephone; // Always Present
039
040    public ContactTelephoneObject(BasePK basePrimaryKey, ContactTelephone contactTelephone) {
041        this.basePrimaryKey = basePrimaryKey;
042        this.contactTelephone = contactTelephone;
043    }
044
045    @GraphQLField
046    @GraphQLDescription("country geo code")
047    public GeoCodeObject getCountryGeoCode(final DataFetchingEnvironment env) {
048        if(GeoSecurityUtils.getHasGeoCodeAccess(env)) {
049            return new GeoCodeObject(contactTelephone.getCountryGeoCode());
050        } else {
051            return null;
052        }
053    }
054
055    @GraphQLField
056    @GraphQLDescription("area code")
057    public String getAreaCode() {
058        return contactTelephone.getAreaCode();
059    }
060
061    @GraphQLField
062    @GraphQLDescription("telephone number")
063    public String getTelephoneNumber() {
064        return contactTelephone.getTelephoneNumber();
065    }
066
067    @GraphQLField
068    @GraphQLDescription("telephone extension")
069    public String getTelephoneExtension() {
070        return contactTelephone.getTelephoneExtension();
071    }
072
073    @GraphQLField
074    @GraphQLDescription("telephone status")
075    public WorkflowEntityStatusObject getTelephoneStatus(final DataFetchingEnvironment env) {
076        return getWorkflowEntityStatusObject(env, basePrimaryKey, TelephoneStatusConstants.Workflow_TELEPHONE_STATUS);
077    }
078
079}