001// --------------------------------------------------------------------------------
002// Copyright 2002-2024 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.party.server.graphql;
018
019import com.echothree.model.control.graphql.server.graphql.BaseEntityInstanceObject;
020import com.echothree.model.data.party.server.entity.NameSuffix;
021import com.echothree.model.data.party.server.entity.NameSuffixDetail;
022import graphql.annotations.annotationTypes.GraphQLDescription;
023import graphql.annotations.annotationTypes.GraphQLField;
024import graphql.annotations.annotationTypes.GraphQLName;
025import graphql.annotations.annotationTypes.GraphQLNonNull;
026
027@GraphQLDescription("name suffix object")
028@GraphQLName("NameSuffix")
029public class NameSuffixObject
030        extends BaseEntityInstanceObject {
031    
032    private final NameSuffix nameSuffix; // Always Present
033    
034    public NameSuffixObject(NameSuffix nameSuffix) {
035        super(nameSuffix.getPrimaryKey());
036
037        this.nameSuffix = nameSuffix;
038    }
039
040    private NameSuffixDetail nameSuffixDetail; // Optional, use getNameSuffixDetail()
041    
042    private NameSuffixDetail getNameSuffixDetail() {
043        if(nameSuffixDetail == null) {
044            nameSuffixDetail = nameSuffix.getLastDetail();
045        }
046        
047        return nameSuffixDetail;
048    }
049
050    @GraphQLField
051    @GraphQLDescription("name suffix id")
052    @GraphQLNonNull
053    public String getNameSuffixId() {
054        return Long.toString(nameSuffix.getPrimaryKey().getEntityId());
055    }
056    
057    @GraphQLField
058    @GraphQLDescription("description")
059    @GraphQLNonNull
060    public String getDescription() {
061        return getNameSuffixDetail().getDescription();
062    }
063
064    @GraphQLField
065    @GraphQLDescription("is default")
066    @GraphQLNonNull
067    public boolean getIsDefault() {
068        return getNameSuffixDetail().getIsDefault();
069    }
070    
071    @GraphQLField
072    @GraphQLDescription("sort order")
073    @GraphQLNonNull
074    public int getSortOrder() {
075        return getNameSuffixDetail().getSortOrder();
076    }
077
078}