# SPDX-FileCopyrightText: 2025 diffo_example contributors # # SPDX-License-Identifier: MIT defmodule DiffoExample.Nbn.NniGroup do @moduledoc """ Diffo - TMF Service and Resource Management with a difference NniGroup - NNI Group Resource Instance An NNI Group is the Point of Interconnect (PoI) grouping where a CVC terminates. It comprises multiple NNI resources. The NNI Group assigns svlan to CVC. """ alias Diffo.Provider.BaseInstance alias Diffo.Provider.Assignment alias DiffoExample.Nbn use Ash.Resource, fragments: [BaseInstance], domain: Nbn, authorizers: [Ash.Policy.Authorizer] resource do description "An Ash Resource representing an NNI Group" plural_name :NniGroups end provider do specification do id "e5f6a7b8-9c0d-4e1f-8a2b-4c5d6e7f8a9b" name "nniGroup" type :resourceSpecification description "An NNI Group Resource Instance comprising multiple NNI resources" category "Network Resource" end characteristics do characteristic :nni_group, DiffoExample.Nbn.NniGroupCharacteristic characteristic :metrics, DiffoExample.Nbn.NniGroupMetrics end pools do pool :svlans, :svlan end relationships do source :all target :all end behaviour do actions do create :build end end end actions do create :build do description "creates a new NNI Group resource instance" accept [:id, :name, :which] argument :relationships, {:array, :struct} argument :places, {:array, :struct} argument :parties, {:array, :struct} change set_attribute(:type, :resource) change DiffoExample.Nbn.Changes.SetRspId change load [:href] upsert? false end update :define do description "defines the NNI Group" argument :characteristic_value_updates, {:array, :term} change set_attribute(:resource_state, :operating) change Diffo.Provider.Changes.Define end update :assign_svlan do description "assigns an S-VLAN ID from the NNI Group pool to a CVC" argument :assignment, :struct, constraints: [instance_of: Assignment] change {Diffo.Provider.Changes.Assign, pool: :svlans} end update :relate do description "relates the NNI Group with other instances (e.g. NNI resources it comprises)" argument :relationships, {:array, :struct} change Diffo.Provider.Changes.Relate end end attributes do attribute :rsp_id, :string do description "the owning RSP's id — nil for Perentie-managed infrastructure" allow_nil? true public? true end end calculations do # The NNI characteristic value of every NNI this NniGroup comprises — # forward traversal of :contains Relationships (low cardinality). calculate :nnis, {:array, :map}, {DiffoExample.Calculations.InheritedCharacteristicViaRelationship, [type: :contains, characteristic_module: DiffoExample.Nbn.NniCharacteristic]} do public? true end end use DiffoExample.Nbn.RspOwnership end