/**
 * Financial Services Data Domain Example
 *
 * This file demonstrates how to create a comprehensive financial services data domain
 * using the API Client Core modeling system. It follows the business-first approach
 * and demonstrates proper use of namespaces, models, entities, properties,
 * associations, and semantic annotations.
 *
 * The example includes:
 * - Account Management with bank accounts, investment accounts, and credit cards
 * - Transaction Processing with payments, transfers, deposits, and withdrawals
 * - Customer Management with KYC, risk profiles, and customer segments
 * - Investment Portfolio with assets, positions, and performance tracking
 * - Compliance & Reporting with regulatory reporting and audit trails
 * - Fraud Detection with transaction monitoring and risk scoring
 *
 * @example
 * ```typescript
 * import { createFinancialServicesDomain } from './financial-services-domain.js'
 *
 * const domain = createFinancialServicesDomain()
 * console.log('Financial Services domain created with', domain.graph.nodeCount(), 'nodes')
 * ```
 */
import { DataDomain } from '../../../DataDomain.js';
import { SemanticType } from '../../../Semantics.js';
import { addIdField, addNameField, addDescriptionField, addEmailField, addFirstNameField, addLastNameField, addPhoneField, addCustomStatusField, addCreatedAtField, addUpdatedAtField, addCurrencyAmountField, } from '../../../helpers/Intelisense.js';
function createDomain() {
    return new DataDomain({
        info: {
            name: 'Financial Services Platform',
            displayName: 'Financial Services Platform',
            description: 'A comprehensive financial services platform with account management, transaction processing, ' +
                'customer management, investment portfolios, and compliance features',
        },
    });
}
/**
 * Creates a comprehensive financial services data domain following domain-driven design principles.
 *
 * This function demonstrates the proper hierarchy and organization for a financial services platform:
 * 1. Creates the root DataDomain for the financial services platform
 * 2. Organizes functionality into logical namespaces (Customer Management, Account Management, etc.)
 * 3. Groups related entities into models within each namespace
 * 4. Defines entities with proper semantic annotations for financial workflows
 * 5. Establishes associations with appropriate cardinality for customer-account relationships
 *
 * @returns A fully configured DataDomain with all financial services entities and relationships
 */
export default function createFinancialServicesDomain(options = {}) {
    // Ensure the root data domain
    const domain = options.domain ?? createDomain();
    //
    // 1. USER & AUTHENTICATION NAMESPACE (Unified for customers and employees)
    //
    const userManagement = domain.addNamespace({
        info: {
            name: 'User Management',
            displayName: 'User & Authentication Management',
            description: 'Unified user authentication, roles, and profile management for customers and employees',
        },
    });
    // Authentication Model
    const authModel = userManagement.addModel({
        info: {
            name: 'Authentication',
            displayName: 'Authentication & Access Control',
            description: 'User authentication, sessions, and access control',
        },
    });
    // Unified User Entity (replaces separate Customer and Employee entities)
    const userEntity = authModel.addEntity({
        info: {
            name: 'user',
            displayName: 'User',
            description: 'Unified user entity for both customers and employees with role-based access',
        },
        semantics: [{ id: SemanticType.User }], // Mark as a user entity for automatic behaviors
    });
    addIdField(userEntity, { displayName: 'User ID', description: 'Unique identifier for the user' });
    // Authentication fields
    userEntity.addProperty({
        info: { name: 'username', displayName: 'Username', description: 'Unique username for login' },
        type: 'string',
        required: true,
        unique: true,
    });
    userEntity.addProperty({
        info: { name: 'password', displayName: 'Password', description: 'User password (hashed)' },
        type: 'string',
        required: true,
        writeOnly: true,
        semantics: [{ id: SemanticType.Password }], // Automatic password security behaviors
    });
    const emailProperty = addEmailField(userEntity, { description: 'User email address' });
    emailProperty.required = true;
    emailProperty.unique = true;
    // Personal Information
    addFirstNameField(userEntity, { description: 'User first name' });
    addLastNameField(userEntity, { description: 'User last name' });
    addPhoneField(userEntity, { description: 'User phone number' });
    // User Type & Role (unified approach)
    userEntity.addProperty({
        info: { name: 'user_type', displayName: 'User Type', description: 'Type of user account' },
        type: 'string',
        required: true,
        schema: {
            enum: ['customer', 'employee', 'admin', 'system'],
        },
    });
    userEntity.addProperty({
        info: { name: 'role', displayName: 'User Role', description: 'User role defining permissions and access level' },
        type: 'string',
        required: true,
        schema: {
            enum: [
                // Customer roles
                'individual_customer',
                'business_customer',
                'premium_customer',
                'private_banking_customer',
                // Employee roles
                'teller',
                'loan_officer',
                'relationship_manager',
                'compliance_officer',
                'branch_manager',
                'investment_advisor',
                'risk_analyst',
                // Admin roles
                'system_admin',
                'security_admin',
                'audit_admin',
            ],
        },
        semantics: [{ id: SemanticType.UserRole }],
    });
    // Status and verification
    addCustomStatusField(userEntity, ['active', 'inactive', 'suspended', 'pending_verification', 'locked'], {
        displayName: 'User Status',
        description: 'Current status of the user account',
    });
    userEntity.addProperty({
        info: { name: 'email_verified', displayName: 'Email Verified', description: 'Whether user email is verified' },
        type: 'boolean',
        required: true,
    });
    userEntity.addProperty({
        info: { name: 'last_login', displayName: 'Last Login', description: 'When user last logged in' },
        type: 'datetime',
    });
    addCreatedAtField(userEntity, { description: 'When the user account was created' });
    addUpdatedAtField(userEntity, { description: 'When the user account was last updated' });
    // Session Entity for authentication management
    const sessionEntity = authModel.addEntity({
        info: {
            name: 'user_session',
            displayName: 'User Session',
            description: 'Active user authentication sessions',
        },
    });
    addIdField(sessionEntity, { displayName: 'Session ID', description: 'Unique session identifier' });
    sessionEntity.addProperty({
        info: { name: 'token', displayName: 'Session Token', description: 'Authentication token for the session' },
        type: 'string',
        required: true,
        writeOnly: true,
    });
    sessionEntity.addProperty({
        info: { name: 'expires_at', displayName: 'Expires At', description: 'When the session expires' },
        type: 'datetime',
        required: true,
    });
    sessionEntity.addProperty({
        info: { name: 'ip_address', displayName: 'IP Address', description: 'IP address of the session' },
        type: 'string',
        semantics: [{ id: SemanticType.ClientIPAddress }],
    });
    addCreatedAtField(sessionEntity, { description: 'When the session was created' });
    // User-Session Association
    userEntity.addAssociation({ key: sessionEntity.key }, {
        info: { name: 'sessions', displayName: 'User Sessions', description: 'Active sessions for this user' },
        required: false,
        multiple: true,
    });
    // Profile Model (for extended user information)
    const profileModel = userManagement.addModel({
        info: {
            name: 'User Profiles',
            displayName: 'User Profile Management',
            description: 'Extended user profile information and preferences',
        },
    });
    // Customer Profile Entity (for customer-specific information)
    const customerProfileEntity = profileModel.addEntity({
        info: {
            name: 'customer_profile',
            displayName: 'Customer Profile',
            description: 'Additional profile information specific to customers',
        },
    });
    addIdField(customerProfileEntity, { displayName: 'Profile ID', description: 'Unique profile identifier' });
    customerProfileEntity.addProperty({
        info: { name: 'date_of_birth', displayName: 'Date of Birth', description: 'Customer date of birth' },
        type: 'date',
        required: true,
    });
    customerProfileEntity.addProperty({
        info: { name: 'ssn', displayName: 'Social Security Number', description: 'Customer SSN for identification' },
        type: 'string',
        required: true,
        writeOnly: true,
    });
    customerProfileEntity.addProperty({
        info: { name: 'address', displayName: 'Address', description: 'Customer residential address' },
        type: 'string',
        required: true,
    });
    customerProfileEntity.addProperty({
        info: { name: 'city', displayName: 'City', description: 'Customer city' },
        type: 'string',
        required: true,
    });
    customerProfileEntity.addProperty({
        info: { name: 'state', displayName: 'State', description: 'Customer state' },
        type: 'string',
        required: true,
    });
    customerProfileEntity.addProperty({
        info: { name: 'zip_code', displayName: 'ZIP Code', description: 'Customer ZIP code' },
        type: 'string',
        required: true,
    });
    customerProfileEntity.addProperty({
        info: { name: 'customer_type', displayName: 'Customer Type', description: 'Type of customer account' },
        type: 'string',
        required: true,
        schema: {
            enum: ['individual', 'business', 'trust', 'partnership'],
        },
    });
    addCreatedAtField(customerProfileEntity, { description: 'When the customer profile was created' });
    addUpdatedAtField(customerProfileEntity, { description: 'When the customer profile was last updated' });
    // User-CustomerProfile Association (one-to-one for customers)
    userEntity.addAssociation({ key: customerProfileEntity.key }, {
        info: {
            name: 'customer_profile',
            displayName: 'Customer Profile',
            description: 'Extended customer profile information',
        },
        required: false, // Only for customers, not employees
        multiple: false,
    });
    // Employee Profile Entity (for employee-specific information)
    const employeeProfileEntity = profileModel.addEntity({
        info: {
            name: 'employee_profile',
            displayName: 'Employee Profile',
            description: 'Additional profile information specific to employees',
        },
    });
    addIdField(employeeProfileEntity, {
        displayName: 'Employee Profile ID',
        description: 'Unique employee profile identifier',
    });
    employeeProfileEntity.addProperty({
        info: { name: 'employee_id', displayName: 'Employee ID', description: 'Company employee identifier' },
        type: 'string',
        required: true,
        unique: true,
    });
    employeeProfileEntity.addProperty({
        info: { name: 'department', displayName: 'Department', description: 'Employee department' },
        type: 'string',
        required: true,
        schema: {
            enum: [
                'retail_banking',
                'commercial_banking',
                'investment_services',
                'risk_management',
                'compliance',
                'operations',
                'technology',
                'human_resources',
                'legal',
            ],
        },
    });
    employeeProfileEntity.addProperty({
        info: { name: 'hire_date', displayName: 'Hire Date', description: 'Employee hire date' },
        type: 'date',
        required: true,
    });
    employeeProfileEntity.addProperty({
        info: { name: 'manager_id', displayName: 'Manager ID', description: 'Employee manager identifier' },
        type: 'string',
    });
    addCreatedAtField(employeeProfileEntity, { description: 'When the employee profile was created' });
    addUpdatedAtField(employeeProfileEntity, { description: 'When the employee profile was last updated' });
    // User-EmployeeProfile Association (one-to-one for employees)
    userEntity.addAssociation({ key: employeeProfileEntity.key }, {
        info: {
            name: 'employee_profile',
            displayName: 'Employee Profile',
            description: 'Extended employee profile information',
        },
        required: false, // Only for employees, not customers
        multiple: false,
    });
    // KYC Entity (enhanced for the unified approach)
    const kycEntity = profileModel.addEntity({
        info: {
            name: 'kyc_record',
            displayName: 'KYC Record',
            description: 'Know Your Customer verification and documentation',
        },
    });
    addIdField(kycEntity, { displayName: 'KYC ID', description: 'Unique identifier for the KYC record' });
    addCustomStatusField(kycEntity, ['pending', 'verified', 'rejected', 'expired'], {
        displayName: 'KYC Status',
        description: 'Current status of KYC verification',
    });
    kycEntity.addProperty({
        info: { name: 'verification_date', displayName: 'Verification Date', description: 'Date when KYC was verified' },
        type: 'date',
    });
    kycEntity.addProperty({
        info: { name: 'document_type', displayName: 'Document Type', description: 'Type of identification document' },
        type: 'string',
        required: true,
        schema: {
            enum: ['passport', 'drivers_license', 'national_id', 'utility_bill', 'bank_statement'],
        },
    });
    kycEntity.addProperty({
        info: { name: 'document_number', displayName: 'Document Number', description: 'Document identification number' },
        type: 'string',
        required: true,
    });
    addCreatedAtField(kycEntity, { description: 'When the KYC record was created' });
    addUpdatedAtField(kycEntity, { description: 'When the KYC record was last updated' });
    // KYC-User Association (One-to-One)
    kycEntity.addAssociation({ key: userEntity.key }, {
        info: { name: 'user', displayName: 'User', description: 'User for this KYC record' },
        required: true,
        multiple: false,
    });
    // Risk Profile Entity
    const riskProfileEntity = profileModel.addEntity({
        info: {
            name: 'risk_profile',
            displayName: 'Risk Profile',
            description: 'Customer risk assessment and scoring',
        },
    });
    addIdField(riskProfileEntity, {
        displayName: 'Risk Profile ID',
        description: 'Unique identifier for the risk profile',
    });
    riskProfileEntity.addProperty({
        info: { name: 'risk_score', displayName: 'Risk Score', description: 'Numerical risk score (1-100)' },
        type: 'number',
        required: true,
        schema: {
            minimum: 1,
            maximum: 100,
        },
    });
    addCustomStatusField(riskProfileEntity, ['low', 'medium', 'high', 'very_high'], {
        displayName: 'Risk Level',
        description: 'Risk level classification',
    });
    riskProfileEntity.addProperty({
        info: { name: 'assessment_date', displayName: 'Assessment Date', description: 'Date when risk was assessed' },
        type: 'date',
        required: true,
    });
    addDescriptionField(riskProfileEntity, { description: 'Risk assessment notes and factors' });
    addCreatedAtField(riskProfileEntity, { description: 'When the risk profile was created' });
    addUpdatedAtField(riskProfileEntity, { description: 'When the risk profile was last updated' });
    // RiskProfile-User Association (One-to-One)
    riskProfileEntity.addAssociation({ key: userEntity.key }, {
        info: { name: 'user', displayName: 'User', description: 'User for this risk profile' },
        required: true,
        multiple: false,
    });
    //
    // 2. ACCOUNT MANAGEMENT NAMESPACE
    //
    const accountManagement = domain.addNamespace({
        info: {
            name: 'AccountManagement',
            displayName: 'Account Management',
            description: 'Bank accounts, investment accounts, and credit cards',
        },
    });
    // Account Model
    const accountModel = accountManagement.addModel({
        info: {
            name: 'Accounts',
            displayName: 'Account Management',
            description: 'Financial accounts and products',
        },
    });
    // Bank Account Entity
    const bankAccountEntity = accountModel.addEntity({
        info: {
            name: 'bank_account',
            displayName: 'Bank Account',
            description: 'Checking and savings accounts',
        },
    });
    addIdField(bankAccountEntity, { displayName: 'Account ID', description: 'Unique identifier for the account' });
    bankAccountEntity.addProperty({
        info: { name: 'account_number', displayName: 'Account Number', description: 'Bank account number' },
        type: 'string',
        required: true,
        unique: true,
    });
    bankAccountEntity.addProperty({
        info: { name: 'routing_number', displayName: 'Routing Number', description: 'Bank routing number' },
        type: 'string',
        required: true,
    });
    bankAccountEntity.addProperty({
        info: { name: 'account_type', displayName: 'Account Type', description: 'Type of bank account' },
        type: 'string',
        required: true,
        schema: {
            enum: ['checking', 'savings', 'money_market', 'cd'],
        },
    });
    addCurrencyAmountField(bankAccountEntity, 'balance', 'Account Balance', {
        description: 'Current account balance',
    });
    addCurrencyAmountField(bankAccountEntity, 'available_balance', 'Available Balance', {
        description: 'Available balance for transactions',
    });
    addCustomStatusField(bankAccountEntity, ['active', 'inactive', 'frozen', 'closed'], {
        displayName: 'Account Status',
        description: 'Current status of the account',
    });
    addCreatedAtField(bankAccountEntity, { description: 'When the account was created' });
    addUpdatedAtField(bankAccountEntity, { description: 'When the account was last updated' });
    // BankAccount-User Association (Many-to-One)
    bankAccountEntity.addAssociation({ key: userEntity.key }, {
        info: { name: 'user', displayName: 'Account Holder', description: 'User who owns this account' },
        required: true,
        multiple: false,
    });
    // Investment Account Entity
    const investmentAccountEntity = accountModel.addEntity({
        info: {
            name: 'investment_account',
            displayName: 'Investment Account',
            description: 'Investment and brokerage accounts',
        },
    });
    addIdField(investmentAccountEntity, {
        displayName: 'Investment Account ID',
        description: 'Unique identifier for the investment account',
    });
    investmentAccountEntity.addProperty({
        info: { name: 'account_number', displayName: 'Account Number', description: 'Investment account number' },
        type: 'string',
        required: true,
        unique: true,
    });
    investmentAccountEntity.addProperty({
        info: { name: 'account_type', displayName: 'Account Type', description: 'Type of investment account' },
        type: 'string',
        required: true,
        schema: {
            enum: ['individual', 'joint', 'ira', '401k', 'roth_ira'],
        },
    });
    addCurrencyAmountField(investmentAccountEntity, 'total_value', 'Total Portfolio Value', {
        description: 'Total value of all investments',
    });
    addCurrencyAmountField(investmentAccountEntity, 'cash_balance', 'Cash Balance', {
        description: 'Available cash balance',
    });
    addCustomStatusField(investmentAccountEntity, ['active', 'inactive', 'suspended', 'closed'], {
        displayName: 'Account Status',
        description: 'Current status of the investment account',
    });
    addCreatedAtField(investmentAccountEntity, { description: 'When the investment account was created' });
    // InvestmentAccount-User Association (Many-to-One)
    investmentAccountEntity.addAssociation({ key: userEntity.key }, {
        info: {
            name: 'user',
            displayName: 'Account Holder',
            description: 'User who owns this investment account',
        },
        required: true,
        multiple: false,
    });
    // Credit Card Entity
    const creditCardEntity = accountModel.addEntity({
        info: {
            name: 'credit_card',
            displayName: 'Credit Card',
            description: 'Credit card accounts and lines of credit',
        },
    });
    addIdField(creditCardEntity, { displayName: 'Credit Card ID', description: 'Unique identifier for the credit card' });
    creditCardEntity.addProperty({
        info: { name: 'card_number', displayName: 'Card Number', description: 'Credit card number (masked)' },
        type: 'string',
        required: true,
        writeOnly: true, // Sensitive data - write only
    });
    addCurrencyAmountField(creditCardEntity, 'credit_limit', 'Credit Limit', {
        description: 'Total credit limit',
    });
    addCurrencyAmountField(creditCardEntity, 'available_credit', 'Available Credit', {
        description: 'Available credit remaining',
    });
    addCurrencyAmountField(creditCardEntity, 'current_balance', 'Current Balance', {
        description: 'Current outstanding balance',
    });
    creditCardEntity.addProperty({
        info: { name: 'apr', displayName: 'APR', description: 'Annual Percentage Rate' },
        type: 'number',
        required: true,
        schema: {
            minimum: 0,
            maximum: 100,
        },
    });
    addCustomStatusField(creditCardEntity, ['active', 'inactive', 'suspended', 'closed'], {
        displayName: 'Card Status',
        description: 'Current status of the credit card',
    });
    addCreatedAtField(creditCardEntity, { description: 'When the credit card was created' });
    // CreditCard-User Association (Many-to-One)
    creditCardEntity.addAssociation({ key: userEntity.key }, {
        info: { name: 'user', displayName: 'Cardholder', description: 'User who owns this credit card' },
        required: true,
        multiple: false,
    });
    //
    // 3. TRANSACTION PROCESSING NAMESPACE
    //
    const transactionProcessing = domain.addNamespace({
        info: {
            name: 'Transaction Processing',
            displayName: 'Transaction Processing',
            description: 'Payments, transfers, deposits, and withdrawals',
        },
    });
    // Transaction Model
    const transactionModel = transactionProcessing.addModel({
        info: {
            name: 'Transactions',
            displayName: 'Transaction Management',
            description: 'Financial transactions and transfers',
        },
    });
    // Transaction Entity
    const transactionEntity = transactionModel.addEntity({
        info: {
            name: 'transaction',
            displayName: 'Transaction',
            description: 'Financial transaction record',
        },
    });
    addIdField(transactionEntity, { displayName: 'Transaction ID', description: 'Unique identifier for the transaction' });
    transactionEntity.addProperty({
        info: {
            name: 'transaction_number',
            displayName: 'Transaction Number',
            description: 'Human-readable transaction number',
        },
        type: 'string',
        required: true,
        unique: true,
    });
    addCustomStatusField(transactionEntity, ['pending', 'processing', 'completed', 'failed', 'cancelled'], {
        displayName: 'Transaction Status',
        description: 'Current status of the transaction',
    });
    transactionEntity.addProperty({
        info: { name: 'transaction_type', displayName: 'Transaction Type', description: 'Type of financial transaction' },
        type: 'string',
        required: true,
        schema: {
            enum: ['deposit', 'withdrawal', 'transfer', 'payment', 'fee'],
        },
    });
    addCurrencyAmountField(transactionEntity, 'amount', 'Transaction Amount', {
        description: 'Amount of the transaction',
    });
    transactionEntity.addProperty({
        info: { name: 'description', displayName: 'Description', description: 'Transaction description' },
        type: 'string',
    });
    transactionEntity.addProperty({
        info: { name: 'transaction_date', displayName: 'Transaction Date', description: 'Date when transaction occurred' },
        type: 'date',
        required: true,
    });
    transactionEntity.addProperty({
        info: { name: 'reference_number', displayName: 'Reference Number', description: 'External reference number' },
        type: 'string',
    });
    addCreatedAtField(transactionEntity, { description: 'When the transaction was created' });
    // Transaction-User Association (Many-to-One)
    transactionEntity.addAssociation({ key: userEntity.key }, {
        info: { name: 'user', displayName: 'User', description: 'User who initiated the transaction' },
        required: true,
        multiple: false,
    });
    // Transaction-Account Association (Many-to-One)
    transactionEntity.addAssociation({ key: bankAccountEntity.key }, {
        info: { name: 'account', displayName: 'Account', description: 'Account involved in the transaction' },
        required: true,
        multiple: false,
    });
    // Transfer Entity
    const transferEntity = transactionModel.addEntity({
        info: {
            name: 'transfer',
            displayName: 'Transfer',
            description: 'Money transfers between accounts',
        },
    });
    addIdField(transferEntity, { displayName: 'Transfer ID', description: 'Unique identifier for the transfer' });
    addCustomStatusField(transferEntity, ['pending', 'processing', 'completed', 'failed', 'cancelled'], {
        displayName: 'Transfer Status',
        description: 'Current status of the transfer',
    });
    addCurrencyAmountField(transferEntity, 'amount', 'Transfer Amount', {
        description: 'Amount being transferred',
    });
    transferEntity.addProperty({
        info: { name: 'transfer_date', displayName: 'Transfer Date', description: 'Date when transfer was initiated' },
        type: 'date',
        required: true,
    });
    addCreatedAtField(transferEntity, { description: 'When the transfer was created' });
    // Transfer-From Account Association (Many-to-One)
    transferEntity.addAssociation({ key: bankAccountEntity.key }, {
        info: { name: 'from_account', displayName: 'From Account', description: 'Source account for the transfer' },
        required: true,
        multiple: false,
    });
    // Transfer-To Account Association (Many-to-One)
    transferEntity.addAssociation({ key: bankAccountEntity.key }, {
        info: { name: 'to_account', displayName: 'To Account', description: 'Destination account for the transfer' },
        required: true,
        multiple: false,
    });
    //
    // 4. INVESTMENT PORTFOLIO NAMESPACE
    //
    const investmentPortfolio = domain.addNamespace({
        info: {
            name: 'Investment Portfolio',
            displayName: 'Investment Portfolio',
            description: 'Assets, positions, and performance tracking',
        },
    });
    // Portfolio Model
    const portfolioModel = investmentPortfolio.addModel({
        info: {
            name: 'Portfolios',
            displayName: 'Portfolio Management',
            description: 'Investment portfolios and assets',
        },
    });
    // Asset Entity
    const assetEntity = portfolioModel.addEntity({
        info: {
            name: 'asset',
            displayName: 'Asset',
            description: 'Investment asset (stocks, bonds, etc.)',
        },
    });
    addIdField(assetEntity, { displayName: 'Asset ID', description: 'Unique identifier for the asset' });
    assetEntity.addProperty({
        info: { name: 'symbol', displayName: 'Symbol', description: 'Asset symbol/ticker' },
        type: 'string',
        required: true,
        unique: true,
    });
    addNameField(assetEntity, { displayName: 'Asset Name', description: 'Name of the asset' });
    assetEntity.addProperty({
        info: { name: 'asset_type', displayName: 'Asset Type', description: 'Type of investment asset' },
        type: 'string',
        required: true,
        schema: {
            enum: ['stock', 'bond', 'etf', 'mutual_fund', 'commodity', 'crypto'],
        },
    });
    addCurrencyAmountField(assetEntity, 'current_price', 'Current Price', {
        description: 'Current market price of the asset',
    });
    addCurrencyAmountField(assetEntity, 'market_cap', 'Market Cap', {
        description: 'Market capitalization',
    });
    addCreatedAtField(assetEntity, { description: 'When the asset was created' });
    // Position Entity
    const positionEntity = portfolioModel.addEntity({
        info: {
            name: 'position',
            displayName: 'Position',
            description: 'Investment position in a portfolio',
        },
    });
    addIdField(positionEntity, { displayName: 'Position ID', description: 'Unique identifier for the position' });
    positionEntity.addProperty({
        info: { name: 'quantity', displayName: 'Quantity', description: 'Number of shares/units held' },
        type: 'number',
        required: true,
        schema: {
            minimum: 0,
        },
    });
    addCurrencyAmountField(positionEntity, 'average_cost', 'Average Cost', {
        description: 'Average cost per share/unit',
    });
    addCurrencyAmountField(positionEntity, 'current_value', 'Current Value', {
        description: 'Current market value of the position',
    });
    addCurrencyAmountField(positionEntity, 'unrealized_gain_loss', 'Unrealized Gain/Loss', {
        description: 'Unrealized profit or loss',
    });
    addCreatedAtField(positionEntity, { description: 'When the position was created' });
    // Position-InvestmentAccount Association (Many-to-One)
    positionEntity.addAssociation({ key: investmentAccountEntity.key }, {
        info: { name: 'account', displayName: 'Investment Account', description: 'Account holding this position' },
        required: true,
        multiple: false,
    });
    // Position-Asset Association (Many-to-One)
    positionEntity.addAssociation({ key: assetEntity.key }, {
        info: { name: 'asset', displayName: 'Asset', description: 'Asset for this position' },
        required: true,
        multiple: false,
    });
    // Performance Entity
    const performanceEntity = portfolioModel.addEntity({
        info: {
            name: 'performance',
            displayName: 'Performance',
            description: 'Portfolio performance tracking',
        },
    });
    addIdField(performanceEntity, {
        displayName: 'Performance ID',
        description: 'Unique identifier for the performance record',
    });
    performanceEntity.addProperty({
        info: { name: 'date', displayName: 'Date', description: 'Date of performance measurement' },
        type: 'date',
        required: true,
    });
    addCurrencyAmountField(performanceEntity, 'total_value', 'Total Value', {
        description: 'Total portfolio value on this date',
    });
    performanceEntity.addProperty({
        info: { name: 'return_percentage', displayName: 'Return Percentage', description: 'Percentage return' },
        type: 'number',
        required: true,
        schema: {
            minimum: -100,
            maximum: 1000,
        },
    });
    addCreatedAtField(performanceEntity, { description: 'When the performance record was created' });
    // Performance-InvestmentAccount Association (Many-to-One)
    performanceEntity.addAssociation({ key: investmentAccountEntity.key }, {
        info: { name: 'account', displayName: 'Investment Account', description: 'Account for this performance record' },
        required: true,
        multiple: false,
    });
    //
    // 5. COMPLIANCE & REPORTING NAMESPACE
    //
    const complianceReporting = domain.addNamespace({
        info: {
            name: 'Compliance Reporting',
            displayName: 'Compliance & Reporting',
            description: 'Regulatory reporting and audit trails',
        },
    });
    // Compliance Model
    const complianceModel = complianceReporting.addModel({
        info: {
            name: 'Compliance',
            displayName: 'Compliance Management',
            description: 'Regulatory compliance and reporting',
        },
    });
    // Audit Trail Entity
    const auditTrailEntity = complianceModel.addEntity({
        info: {
            name: 'audit_trail',
            displayName: 'Audit Trail',
            description: 'System audit trail for compliance',
        },
    });
    addIdField(auditTrailEntity, { displayName: 'Audit ID', description: 'Unique identifier for the audit record' });
    auditTrailEntity.addProperty({
        info: { name: 'action', displayName: 'Action', description: 'Action performed' },
        type: 'string',
        required: true,
    });
    auditTrailEntity.addProperty({
        info: { name: 'entity_type', displayName: 'Entity Type', description: 'Type of entity affected' },
        type: 'string',
        required: true,
    });
    auditTrailEntity.addProperty({
        info: { name: 'entity_id', displayName: 'Entity ID', description: 'ID of the affected entity' },
        type: 'string',
        required: true,
    });
    auditTrailEntity.addProperty({
        info: { name: 'user_id', displayName: 'User ID', description: 'User who performed the action' },
        type: 'string',
        required: true,
    });
    auditTrailEntity.addProperty({
        info: { name: 'ip_address', displayName: 'IP Address', description: 'IP address of the user' },
        type: 'string',
        semantics: [{ id: SemanticType.ClientIPAddress }],
    });
    addDescriptionField(auditTrailEntity, { description: 'Additional details about the action' });
    addCreatedAtField(auditTrailEntity, {
        name: 'timestamp',
        displayName: 'Timestamp',
        description: 'When the action occurred',
    });
    // Regulatory Report Entity
    const regulatoryReportEntity = complianceModel.addEntity({
        info: {
            name: 'regulatory_report',
            displayName: 'Regulatory Report',
            description: 'Regulatory reporting requirements',
        },
    });
    addIdField(regulatoryReportEntity, { displayName: 'Report ID', description: 'Unique identifier for the report' });
    addNameField(regulatoryReportEntity, { displayName: 'Report Name', description: 'Name of the regulatory report' });
    addCustomStatusField(regulatoryReportEntity, ['draft', 'submitted', 'approved', 'rejected'], {
        displayName: 'Report Status',
        description: 'Current status of the report',
    });
    regulatoryReportEntity.addProperty({
        info: { name: 'report_type', displayName: 'Report Type', description: 'Type of regulatory report' },
        type: 'string',
        required: true,
        schema: {
            enum: ['suspicious_activity', 'large_transaction', 'annual_report', 'quarterly_report'],
        },
    });
    regulatoryReportEntity.addProperty({
        info: { name: 'reporting_period', displayName: 'Reporting Period', description: 'Period covered by the report' },
        type: 'string',
        required: true,
    });
    addDescriptionField(regulatoryReportEntity, { description: 'Report content and details' });
    addCreatedAtField(regulatoryReportEntity, { description: 'When the report was created' });
    //
    // 6. FRAUD DETECTION NAMESPACE
    //
    const fraudDetection = domain.addNamespace({
        info: {
            name: 'FraudDetection',
            displayName: 'Fraud Detection',
            description: 'Transaction monitoring and risk scoring',
        },
    });
    // Fraud Detection Model
    const fraudDetectionModel = fraudDetection.addModel({
        info: {
            name: 'FraudDetection',
            displayName: 'Fraud Detection Management',
            description: 'Fraud detection and monitoring',
        },
    });
    // Fraud Alert Entity
    const fraudAlertEntity = fraudDetectionModel.addEntity({
        info: {
            name: 'fraud_alert',
            displayName: 'Fraud Alert',
            description: 'Fraud detection alerts and flags',
        },
    });
    addIdField(fraudAlertEntity, { displayName: 'Alert ID', description: 'Unique identifier for the fraud alert' });
    addCustomStatusField(fraudAlertEntity, ['pending', 'investigating', 'resolved', 'false_positive'], {
        displayName: 'Alert Status',
        description: 'Current status of the fraud alert',
    });
    fraudAlertEntity.addProperty({
        info: { name: 'alert_type', displayName: 'Alert Type', description: 'Type of fraud alert' },
        type: 'string',
        required: true,
        schema: {
            enum: ['suspicious_transaction', 'unusual_pattern', 'identity_theft', 'account_takeover'],
        },
    });
    fraudAlertEntity.addProperty({
        info: { name: 'risk_score', displayName: 'Risk Score', description: 'Risk score (1-100)' },
        type: 'number',
        required: true,
        schema: {
            minimum: 1,
            maximum: 100,
        },
    });
    addDescriptionField(fraudAlertEntity, { description: 'Details about the fraud alert' });
    addCreatedAtField(fraudAlertEntity, { description: 'When the fraud alert was created' });
    // FraudAlert-Transaction Association (Many-to-One)
    fraudAlertEntity.addAssociation({ key: transactionEntity.key }, {
        info: { name: 'transaction', displayName: 'Transaction', description: 'Transaction that triggered the alert' },
        required: false,
        multiple: false,
    });
    // FraudAlert-User Association (Many-to-One)
    fraudAlertEntity.addAssociation({ key: userEntity.key }, {
        info: { name: 'user', displayName: 'User', description: 'User associated with the alert' },
        required: true,
        multiple: false,
    });
    return domain;
}
//# sourceMappingURL=financial-services-domain.js.map