001/*
002 * JDrupes Builder
003 * Copyright (C) 2025 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.api;
020
021/// The Interface defines the type used as key for a [Project]'s properties.
022/// Implementations of this interface should extend [Enum]. See
023/// [Project.Properties] for an example.
024///
025public interface PropertyKey {
026
027    /// The property's name.
028    ///
029    /// @return the string
030    ///
031    String name();
032
033    /// The property's type. Returns `Object.class` if both the
034    /// property type and the default value are null.
035    ///
036    /// @return the class
037    ///
038    default Class<?> type() {
039        if (propertyType() != null) {
040            return propertyType();
041        }
042        if (defaultValue() == null) {
043            return Object.class;
044        }
045        return defaultValue().getClass();
046    }
047
048    /// An explicitly set property type. Only required if the default
049    /// value is `null` or the type of the default value is a derived
050    /// class of the desired property type.
051    ///
052    /// @return the class
053    ///
054    default Class<?> propertyType() {
055        return null;
056    }
057
058    /// The property's default value. This value should either not be
059    /// `null` or [propertyType] should return a non-`null` class.
060    ///
061    /// @param <T> the generic type
062    /// @return the object
063    ///
064    <T> T defaultValue();
065
066}