Customer.java

  1. /*
  2.  * *************************************************************************************************************************************************************
  3.  *
  4.  * blueHour: open source accounting
  5.  * http://tidalwave.it/projects/bluehour
  6.  *
  7.  * Copyright (C) 2013 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *************************************************************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  12.  * You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  17.  * CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.
  18.  *
  19.  * *************************************************************************************************************************************************************
  20.  *
  21.  * git clone https://bitbucket.org/tidalwave/bluehour-src
  22.  * git clone https://github.com/tidalwave-it/bluehour-src
  23.  *
  24.  * *************************************************************************************************************************************************************
  25.  */
  26. package it.tidalwave.accounting.model;

  27. import jakarta.annotation.Nonnull;
  28. // import javax.annotation.concurrent.Immutable;
  29. import it.tidalwave.accounting.model.spi.ObjectFactory;
  30. import it.tidalwave.accounting.model.types.Address;
  31. import it.tidalwave.util.As;
  32. import it.tidalwave.util.Id;
  33. import it.tidalwave.role.Identifiable;
  34. import lombok.AllArgsConstructor;
  35. import lombok.Getter;
  36. import lombok.ToString;
  37. import lombok.With;

  38. /***************************************************************************************************************************************************************
  39.  *
  40.  * This class models a customer.
  41.  *
  42.  * @author  Fabrizio Giudici
  43.  *
  44.  **************************************************************************************************************************************************************/
  45. public interface Customer extends Identifiable, As
  46.   {
  47.     /***********************************************************************************************************************************************************
  48.      *
  49.      **********************************************************************************************************************************************************/
  50.     @AllArgsConstructor // FIXME (access = PROTECTED)
  51.     /* @Immutable */ @With @Getter @ToString
  52.     public static class Builder
  53.       {
  54.         public static interface Callback // Lombok @With doesn't support builder subclasses
  55.           {
  56.             public void register (@Nonnull final Customer customer);

  57.             public static final Callback DEFAULT = (customer) -> {};
  58.           }

  59.         private final Id id;
  60.         private final String name;
  61.         private final Address billingAddress;
  62.         private final String vatNumber;
  63.         private final Callback callback;

  64.         public Builder()
  65.           {
  66.             this(Callback.DEFAULT);
  67.           }

  68.         public Builder (@Nonnull final Callback callback)
  69.           {
  70.             this(new Id(""), "", Address.EMPTY, "", callback);
  71.           }

  72.         @Nonnull
  73.         public Builder with (@Nonnull final Builder builder)
  74.           {
  75.             return builder.withCallback(callback);
  76.           }

  77.         @Nonnull
  78.         public Customer create()
  79.           {
  80.             final var customer = ObjectFactory.getInstance().createCustomer(this);
  81.             callback.register(customer);
  82.             return customer;
  83.           }
  84.       }

  85.     /***********************************************************************************************************************************************************
  86.      *
  87.      **********************************************************************************************************************************************************/
  88.     @Nonnull
  89.     public static Builder builder()
  90.       {
  91.         return new Builder();
  92.       }

  93.     /***********************************************************************************************************************************************************
  94.      *
  95.      **********************************************************************************************************************************************************/
  96.     @Nonnull
  97.     public ProjectRegistry.ProjectFinder findProjects();

  98.     /***********************************************************************************************************************************************************
  99.      * Returns a builder pre-populated with all the attributes.
  100.      *
  101.      * @return  the builder
  102.      **********************************************************************************************************************************************************/
  103.     @Nonnull
  104.     public Builder toBuilder();
  105.   }