defmodule Mv.MembershipFees do
  @moduledoc """
  Ash Domain for membership fee management.

  ## Resources
  - `MembershipFeeType` - Defines membership fee types with intervals and amounts
  - `MembershipFeeCycle` - Individual membership fee cycles per member

  ## Public API
  The domain exposes these main actions:
  - MembershipFeeType CRUD: `create_membership_fee_type/1`, `list_membership_fee_types/0`, `update_membership_fee_type/2`, `destroy_membership_fee_type/1`
  - MembershipFeeCycle CRUD: `create_membership_fee_cycle/1`, `list_membership_fee_cycles/0`, `update_membership_fee_cycle/2`, `destroy_membership_fee_cycle/1`

  Note: LiveViews may use direct Ash calls instead of these domain functions for performance or flexibility.

  ## Overview
  This domain handles the complete membership fee lifecycle including:
  - Fee type definitions (monthly, quarterly, half-yearly, yearly)
  - Individual fee cycles for each member
  - Payment status tracking (unpaid, paid, suspended)

  ## Architecture Decisions
  - `interval` field on MembershipFeeType is immutable after creation
  - `cycle_end` is calculated, not stored (from cycle_start + interval)
  - `amount` is stored per cycle for audit trail when prices change
  """
  use Ash.Domain,
    extensions: [AshAdmin.Domain, AshPhoenix]

  admin do
    show? true
  end

  resources do
    resource Mv.MembershipFees.MembershipFeeType do
      define :create_membership_fee_type, action: :create
      define :list_membership_fee_types, action: :read
      define :update_membership_fee_type, action: :update
      define :destroy_membership_fee_type, action: :destroy
    end

    resource Mv.MembershipFees.MembershipFeeCycle do
      define :create_membership_fee_cycle, action: :create
      define :list_membership_fee_cycles, action: :read
      define :update_membership_fee_cycle, action: :update
      define :destroy_membership_fee_cycle, action: :destroy
    end
  end
end
