/**
 * Legal Services Domain Template
 *
 * A comprehensive legal services data domain following domain-driven design principles.
 * This template covers the complete legal practice lifecycle including:
 *
 * - Case Management: Cases, matters, documents, timelines
 * - Client Management: Clients, contacts, billing relationships
 * - Document Management: Contracts, pleadings, evidence
 * - Time Tracking: Billable hours, time entries, rates
 * - Calendar Management: Court dates, deadlines, appointments
 * - Billing & Accounting: Invoicing, payments, trust accounts
 *
 * Key Features:
 * - Complete case lifecycle management
 * - Client relationship management
 * - Document and evidence tracking
 * - Time and billing management
 * - Calendar and deadline management
 * - Trust account management
 * - Legal practice operations
 *
 * Use Cases:
 * - Law firms and legal practices
 * - Legal case management
 * - Client relationship management
 * - Document management
 * - Time and billing tracking
 * - Legal calendar management
 */
import { DataDomain } from '../../../DataDomain.js';
import { addIdField, addNameField, addDescriptionField, addEmailField, addPhoneField, addCustomStatusField, addCreatedAtField, addUpdatedAtField, addCurrencyAmountField, } from '../../../helpers/Intelisense.js';
function createDomain() {
    return new DataDomain({
        info: {
            name: 'Legal Services Platform',
            displayName: 'Legal Services Platform',
            description: 'A comprehensive legal services platform with case management, client relationships, ' +
                'document management, time tracking, calendar management, and billing',
        },
    });
}
/**
 * Creates a comprehensive legal services data domain following domain-driven design principles.
 *
 * This function demonstrates the proper hierarchy and organization for a legal services platform:
 * 1. Creates the root DataDomain for the legal services platform
 * 2. Organizes functionality into logical namespaces (Case Management, Client Management, etc.)
 * 3. Groups related entities into models within each namespace
 * 4. Defines entities with proper semantic annotations for legal workflows
 * 5. Establishes associations with appropriate cardinality for legal relationships
 *
 * @returns A fully configured DataDomain with all legal services entities and relationships
 */
export default function createLegalServicesDomain(options = {}) {
    // Ensure the root data domain
    const domain = options.domain ?? createDomain();
    //
    // 1. CASE MANAGEMENT NAMESPACE
    //
    const caseManagement = domain.addNamespace({
        info: {
            name: 'CaseManagement',
            displayName: 'Case Management',
            description: 'Cases, matters, documents, and timelines',
        },
    });
    // Case Model
    const caseModel = caseManagement.addModel({
        info: {
            name: 'Cases',
            displayName: 'Case Management',
            description: 'Legal cases and matters',
        },
    });
    // Case Entity
    const caseEntity = caseModel.addEntity({
        info: {
            name: 'case',
            displayName: 'Case',
            description: 'Legal case or matter',
        },
    });
    addIdField(caseEntity, { displayName: 'Case ID', description: 'Unique identifier for the case' });
    addNameField(caseEntity, { description: 'Case name and title' });
    addDescriptionField(caseEntity, { description: 'Case description and summary' });
    caseEntity.addProperty({
        info: { name: 'case_number', displayName: 'Case Number', description: 'Official case number' },
        type: 'string',
        required: true,
        unique: true,
    });
    caseEntity.addProperty({
        info: { name: 'case_type', displayName: 'Case Type', description: 'Type of legal case' },
        type: 'string',
        required: true,
        schema: {
            enum: ['civil', 'criminal', 'family', 'corporate', 'real_estate', 'intellectual_property', 'bankruptcy'],
        },
    });
    caseEntity.addProperty({
        info: { name: 'practice_area', displayName: 'Practice Area', description: 'Legal practice area' },
        type: 'string',
        required: true,
        schema: {
            enum: [
                'litigation',
                'corporate',
                'real_estate',
                'family_law',
                'criminal_defense',
                'intellectual_property',
                'bankruptcy',
                'employment',
                'tax',
                'estate_planning',
            ],
        },
    });
    caseEntity.addProperty({
        info: { name: 'filing_date', displayName: 'Filing Date', description: 'Case filing date' },
        type: 'date',
        required: false,
    });
    caseEntity.addProperty({
        info: { name: 'court', displayName: 'Court', description: 'Court where case is filed' },
        type: 'string',
        required: false,
    });
    caseEntity.addProperty({
        info: { name: 'judge', displayName: 'Judge', description: 'Assigned judge' },
        type: 'string',
        required: false,
    });
    addCustomStatusField(caseEntity, ['open', 'pending', 'settled', 'closed', 'appealed'], {
        displayName: 'Case Status',
        description: 'Current status of the case',
    });
    addCreatedAtField(caseEntity, { description: 'When the case was created' });
    addUpdatedAtField(caseEntity, { description: 'When the case was last updated' });
    // Matter Entity
    const matterEntity = caseModel.addEntity({
        info: {
            name: 'matter',
            displayName: 'Matter',
            description: 'Legal matter or sub-case',
        },
    });
    addIdField(matterEntity, { displayName: 'Matter ID', description: 'Unique identifier for the matter' });
    addNameField(matterEntity, { description: 'Matter name and description' });
    addDescriptionField(matterEntity, { description: 'Matter description and details' });
    matterEntity.addProperty({
        info: { name: 'matter_type', displayName: 'Matter Type', description: 'Type of legal matter' },
        type: 'string',
        required: true,
        schema: {
            enum: ['transaction', 'litigation', 'advisory', 'compliance', 'investigation'],
        },
    });
    matterEntity.addProperty({
        info: { name: 'priority', displayName: 'Priority', description: 'Matter priority level' },
        type: 'string',
        required: true,
        schema: {
            enum: ['low', 'medium', 'high', 'urgent'],
        },
    });
    addCustomStatusField(matterEntity, ['active', 'pending', 'completed', 'on_hold'], {
        displayName: 'Matter Status',
        description: 'Current status of the matter',
    });
    addCreatedAtField(matterEntity, { description: 'When the matter was created' });
    // Matter-Case Association (Many-to-One)
    matterEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this matter' },
        required: true,
        multiple: false,
    });
    // Timeline Event Entity
    const timelineEventEntity = caseModel.addEntity({
        info: {
            name: 'timeline_event',
            displayName: 'Timeline Event',
            description: 'Case timeline events and milestones',
        },
    });
    addIdField(timelineEventEntity, {
        displayName: 'Event ID',
        description: 'Unique identifier for the timeline event',
    });
    addNameField(timelineEventEntity, { description: 'Event name and description' });
    addDescriptionField(timelineEventEntity, { description: 'Event description and details' });
    timelineEventEntity.addProperty({
        info: { name: 'event_type', displayName: 'Event Type', description: 'Type of timeline event' },
        type: 'string',
        required: true,
        schema: {
            enum: ['filing', 'hearing', 'discovery', 'settlement', 'trial', 'appeal', 'deadline'],
        },
    });
    timelineEventEntity.addProperty({
        info: { name: 'event_date', displayName: 'Event Date', description: 'Date of the event' },
        type: 'date',
        required: true,
    });
    timelineEventEntity.addProperty({
        info: { name: 'event_time', displayName: 'Event Time', description: 'Time of the event' },
        type: 'time',
        required: false,
    });
    addCustomStatusField(timelineEventEntity, ['scheduled', 'completed', 'cancelled', 'postponed'], {
        displayName: 'Event Status',
        description: 'Current status of the timeline event',
    });
    addCreatedAtField(timelineEventEntity, { description: 'When the event was created' });
    // TimelineEvent-Case Association (Many-to-One)
    timelineEventEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this timeline event' },
        required: true,
        multiple: false,
    });
    //
    // 2. CLIENT MANAGEMENT NAMESPACE
    //
    const clientManagement = domain.addNamespace({
        info: {
            name: 'ClientManagement',
            displayName: 'Client Management',
            description: 'Clients, contacts, and billing relationships',
        },
    });
    // Client Model
    const clientModel = clientManagement.addModel({
        info: {
            name: 'Clients',
            displayName: 'Client Management',
            description: 'Client and contact management',
        },
    });
    // Client Entity
    const clientEntity = clientModel.addEntity({
        info: {
            name: 'client',
            displayName: 'Client',
            description: 'Legal client with contact information',
        },
    });
    addIdField(clientEntity, { displayName: 'Client ID', description: 'Unique identifier for the client' });
    addNameField(clientEntity, { description: 'Client name and title' });
    addDescriptionField(clientEntity, { description: 'Client description and notes' });
    addEmailField(clientEntity, { description: 'Client email address' });
    addPhoneField(clientEntity, { description: 'Client phone number' });
    clientEntity.addProperty({
        info: { name: 'client_type', displayName: 'Client Type', description: 'Type of client' },
        type: 'string',
        required: true,
        schema: {
            enum: ['individual', 'corporation', 'partnership', 'government', 'non_profit'],
        },
    });
    clientEntity.addProperty({
        info: { name: 'address', displayName: 'Address', description: 'Client address' },
        type: 'string',
        required: false,
    });
    clientEntity.addProperty({
        info: { name: 'date_of_birth', displayName: 'Date of Birth', description: 'Client date of birth' },
        type: 'date',
        required: false,
    });
    addCustomStatusField(clientEntity, ['active', 'inactive', 'prospect', 'former'], {
        displayName: 'Client Status',
        description: 'Current status of the client',
    });
    addCreatedAtField(clientEntity, { description: 'When the client record was created' });
    addUpdatedAtField(clientEntity, { description: 'When the client record was last updated' });
    // Contact Entity
    const contactEntity = clientModel.addEntity({
        info: {
            name: 'contact',
            displayName: 'Contact',
            description: 'Client contacts and representatives',
        },
    });
    addIdField(contactEntity, { displayName: 'Contact ID', description: 'Unique identifier for the contact' });
    addNameField(contactEntity, { description: 'Contact name and title' });
    addEmailField(contactEntity, { description: 'Contact email address' });
    addPhoneField(contactEntity, { description: 'Contact phone number' });
    contactEntity.addProperty({
        info: { name: 'contact_type', displayName: 'Contact Type', description: 'Type of contact' },
        type: 'string',
        required: true,
        schema: {
            enum: ['primary', 'secondary', 'emergency', 'billing', 'legal_representative'],
        },
    });
    contactEntity.addProperty({
        info: { name: 'position', displayName: 'Position', description: 'Contact position or role' },
        type: 'string',
        required: false,
    });
    addCustomStatusField(contactEntity, ['active', 'inactive'], {
        displayName: 'Contact Status',
        description: 'Current status of the contact',
    });
    addCreatedAtField(contactEntity, { description: 'When the contact was created' });
    // Contact-Client Association (Many-to-One)
    contactEntity.addAssociation({ key: clientEntity.key }, {
        info: { name: 'client', displayName: 'Client', description: 'Client for this contact' },
        required: true,
        multiple: false,
    });
    // Case-Client Association (Many-to-One)
    caseEntity.addAssociation({ key: clientEntity.key }, {
        info: { name: 'client', displayName: 'Client', description: 'Client for this case' },
        required: true,
        multiple: false,
    });
    //
    // 3. DOCUMENT MANAGEMENT NAMESPACE
    //
    const documentManagement = domain.addNamespace({
        info: {
            name: 'DocumentManagement',
            displayName: 'Document Management',
            description: 'Contracts, pleadings, evidence, and legal documents',
        },
    });
    // Document Model
    const documentModel = documentManagement.addModel({
        info: {
            name: 'Documents',
            displayName: 'Document Management',
            description: 'Legal documents and files',
        },
    });
    // Document Entity
    const documentEntity = documentModel.addEntity({
        info: {
            name: 'document',
            displayName: 'Document',
            description: 'Legal document or file',
        },
    });
    addIdField(documentEntity, { displayName: 'Document ID', description: 'Unique identifier for the document' });
    addNameField(documentEntity, { description: 'Document name and title' });
    addDescriptionField(documentEntity, { description: 'Document description and summary' });
    documentEntity.addProperty({
        info: { name: 'document_type', displayName: 'Document Type', description: 'Type of legal document' },
        type: 'string',
        required: true,
        schema: {
            enum: [
                'contract',
                'pleading',
                'motion',
                'brief',
                'evidence',
                'correspondence',
                'court_order',
                'settlement_agreement',
                'legal_opinion',
                'affidavit',
            ],
        },
    });
    documentEntity.addProperty({
        info: { name: 'file_path', displayName: 'File Path', description: 'Document file path' },
        type: 'string',
        required: true,
    });
    documentEntity.addProperty({
        info: { name: 'file_size', displayName: 'File Size', description: 'Document file size in bytes' },
        type: 'number',
        required: false,
        schema: {
            minimum: 0,
        },
    });
    documentEntity.addProperty({
        info: { name: 'file_format', displayName: 'File Format', description: 'Document file format' },
        type: 'string',
        required: true,
        schema: {
            enum: ['pdf', 'doc', 'docx', 'txt', 'rtf', 'html', 'xml'],
        },
    });
    documentEntity.addProperty({
        info: { name: 'version', displayName: 'Version', description: 'Document version number' },
        type: 'string',
        required: true,
    });
    addCustomStatusField(documentEntity, ['draft', 'final', 'archived', 'superseded'], {
        displayName: 'Document Status',
        description: 'Current status of the document',
    });
    addCreatedAtField(documentEntity, { description: 'When the document was created' });
    addUpdatedAtField(documentEntity, { description: 'When the document was last updated' });
    // Document-Case Association (Many-to-One)
    documentEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this document' },
        required: true,
        multiple: false,
    });
    // Evidence Entity
    const evidenceEntity = documentModel.addEntity({
        info: {
            name: 'evidence',
            displayName: 'Evidence',
            description: 'Legal evidence and exhibits',
        },
    });
    addIdField(evidenceEntity, { displayName: 'Evidence ID', description: 'Unique identifier for the evidence' });
    addNameField(evidenceEntity, { description: 'Evidence name and description' });
    addDescriptionField(evidenceEntity, { description: 'Evidence description and details' });
    evidenceEntity.addProperty({
        info: { name: 'evidence_type', displayName: 'Evidence Type', description: 'Type of evidence' },
        type: 'string',
        required: true,
        schema: {
            enum: ['document', 'physical', 'digital', 'testimony', 'expert_report', 'photograph', 'video'],
        },
    });
    evidenceEntity.addProperty({
        info: { name: 'exhibit_number', displayName: 'Exhibit Number', description: 'Court exhibit number' },
        type: 'string',
        required: false,
    });
    evidenceEntity.addProperty({
        info: { name: 'admitted', displayName: 'Admitted', description: 'Whether evidence was admitted' },
        type: 'boolean',
        required: false,
    });
    addCustomStatusField(evidenceEntity, ['pending', 'admitted', 'excluded', 'withdrawn'], {
        displayName: 'Evidence Status',
        description: 'Current status of the evidence',
    });
    addCreatedAtField(evidenceEntity, { description: 'When the evidence was created' });
    // Evidence-Case Association (Many-to-One)
    evidenceEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this evidence' },
        required: true,
        multiple: false,
    });
    //
    // 4. TIME TRACKING NAMESPACE
    //
    const timeTracking = domain.addNamespace({
        info: {
            name: 'TimeTracking',
            displayName: 'Time Tracking',
            description: 'Billable hours, time entries, and rates',
        },
    });
    // Time Model
    const timeModel = timeTracking.addModel({
        info: {
            name: 'Time',
            displayName: 'Time Tracking',
            description: 'Time tracking and billing',
        },
    });
    // Time Entry Entity
    const timeEntryEntity = timeModel.addEntity({
        info: {
            name: 'time_entry',
            displayName: 'Time Entry',
            description: 'Billable time entry',
        },
    });
    addIdField(timeEntryEntity, { displayName: 'Entry ID', description: 'Unique identifier for the time entry' });
    addNameField(timeEntryEntity, { description: 'Time entry description' });
    timeEntryEntity.addProperty({
        info: { name: 'entry_date', displayName: 'Entry Date', description: 'Date of the time entry' },
        type: 'date',
        required: true,
    });
    timeEntryEntity.addProperty({
        info: { name: 'start_time', displayName: 'Start Time', description: 'Time entry start time' },
        type: 'time',
        required: true,
    });
    timeEntryEntity.addProperty({
        info: { name: 'end_time', displayName: 'End Time', description: 'Time entry end time' },
        type: 'time',
        required: true,
    });
    timeEntryEntity.addProperty({
        info: { name: 'hours', displayName: 'Hours', description: 'Total hours worked' },
        type: 'number',
        required: true,
        schema: {
            minimum: 0,
        },
    });
    timeEntryEntity.addProperty({
        info: { name: 'activity_type', displayName: 'Activity Type', description: 'Type of activity' },
        type: 'string',
        required: true,
        schema: {
            enum: ['research', 'drafting', 'review', 'meeting', 'court_appearance', 'client_communication', 'administrative'],
        },
    });
    addCurrencyAmountField(timeEntryEntity, 'rate', 'Hourly Rate', {
        description: 'Hourly billing rate',
    });
    addCurrencyAmountField(timeEntryEntity, 'amount', 'Total Amount', {
        description: 'Total billable amount',
    });
    addCustomStatusField(timeEntryEntity, ['pending', 'approved', 'billed', 'paid'], {
        displayName: 'Entry Status',
        description: 'Current status of the time entry',
    });
    addCreatedAtField(timeEntryEntity, { description: 'When the time entry was created' });
    // TimeEntry-Case Association (Many-to-One)
    timeEntryEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this time entry' },
        required: true,
        multiple: false,
    });
    // Billing Rate Entity
    const billingRateEntity = timeModel.addEntity({
        info: {
            name: 'billing_rate',
            displayName: 'Billing Rate',
            description: 'Attorney billing rates',
        },
    });
    addIdField(billingRateEntity, { displayName: 'Rate ID', description: 'Unique identifier for the billing rate' });
    addNameField(billingRateEntity, { description: 'Rate name and description' });
    billingRateEntity.addProperty({
        info: { name: 'rate_type', displayName: 'Rate Type', description: 'Type of billing rate' },
        type: 'string',
        required: true,
        schema: {
            enum: ['hourly', 'flat_fee', 'contingency', 'retainer'],
        },
    });
    billingRateEntity.addProperty({
        info: { name: 'effective_date', displayName: 'Effective Date', description: 'Rate effective date' },
        type: 'date',
        required: true,
    });
    addCurrencyAmountField(billingRateEntity, 'rate_amount', 'Rate Amount', {
        description: 'Billing rate amount',
    });
    addCustomStatusField(billingRateEntity, ['active', 'inactive', 'expired'], {
        displayName: 'Rate Status',
        description: 'Current status of the billing rate',
    });
    addCreatedAtField(billingRateEntity, { description: 'When the billing rate was created' });
    //
    // 5. CALENDAR MANAGEMENT NAMESPACE
    //
    const calendarManagement = domain.addNamespace({
        info: {
            name: 'CalendarManagement',
            displayName: 'Calendar Management',
            description: 'Court dates, deadlines, and appointments',
        },
    });
    // Calendar Model
    const calendarModel = calendarManagement.addModel({
        info: {
            name: 'Calendar',
            displayName: 'Calendar Management',
            description: 'Calendar events and scheduling',
        },
    });
    // Calendar Event Entity
    const calendarEventEntity = calendarModel.addEntity({
        info: {
            name: 'calendar_event',
            displayName: 'Calendar Event',
            description: 'Calendar event or appointment',
        },
    });
    addIdField(calendarEventEntity, {
        displayName: 'Event ID',
        description: 'Unique identifier for the calendar event',
    });
    addNameField(calendarEventEntity, { description: 'Event name and title' });
    addDescriptionField(calendarEventEntity, { description: 'Event description and details' });
    calendarEventEntity.addProperty({
        info: { name: 'event_type', displayName: 'Event Type', description: 'Type of calendar event' },
        type: 'string',
        required: true,
        schema: {
            enum: ['court_hearing', 'client_meeting', 'deadline', 'deposition', 'mediation', 'trial', 'appointment'],
        },
    });
    calendarEventEntity.addProperty({
        info: { name: 'event_date', displayName: 'Event Date', description: 'Date of the event' },
        type: 'date',
        required: true,
    });
    calendarEventEntity.addProperty({
        info: { name: 'start_time', displayName: 'Start Time', description: 'Event start time' },
        type: 'time',
        required: true,
    });
    calendarEventEntity.addProperty({
        info: { name: 'end_time', displayName: 'End Time', description: 'Event end time' },
        type: 'time',
        required: false,
    });
    calendarEventEntity.addProperty({
        info: { name: 'location', displayName: 'Location', description: 'Event location' },
        type: 'string',
        required: false,
    });
    calendarEventEntity.addProperty({
        info: { name: 'priority', displayName: 'Priority', description: 'Event priority level' },
        type: 'string',
        required: true,
        schema: {
            enum: ['low', 'medium', 'high', 'critical'],
        },
    });
    addCustomStatusField(calendarEventEntity, ['scheduled', 'confirmed', 'completed', 'cancelled'], {
        displayName: 'Event Status',
        description: 'Current status of the calendar event',
    });
    addCreatedAtField(calendarEventEntity, { description: 'When the event was created' });
    // CalendarEvent-Case Association (Many-to-One)
    calendarEventEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this calendar event' },
        required: false,
        multiple: false,
    });
    // CalendarEvent-Client Association (Many-to-One)
    calendarEventEntity.addAssociation({ key: clientEntity.key }, {
        info: { name: 'client', displayName: 'Client', description: 'Client for this calendar event' },
        required: false,
        multiple: false,
    });
    // Deadline Entity
    const deadlineEntity = calendarModel.addEntity({
        info: {
            name: 'deadline',
            displayName: 'Deadline',
            description: 'Legal deadlines and important dates',
        },
    });
    addIdField(deadlineEntity, { displayName: 'Deadline ID', description: 'Unique identifier for the deadline' });
    addNameField(deadlineEntity, { description: 'Deadline name and description' });
    addDescriptionField(deadlineEntity, { description: 'Deadline description and details' });
    deadlineEntity.addProperty({
        info: { name: 'deadline_type', displayName: 'Deadline Type', description: 'Type of deadline' },
        type: 'string',
        required: true,
        schema: {
            enum: ['filing', 'response', 'discovery', 'appeal', 'statute_of_limitations', 'contract'],
        },
    });
    deadlineEntity.addProperty({
        info: { name: 'due_date', displayName: 'Due Date', description: 'Deadline due date' },
        type: 'date',
        required: true,
    });
    deadlineEntity.addProperty({
        info: { name: 'due_time', displayName: 'Due Time', description: 'Deadline due time' },
        type: 'time',
        required: false,
    });
    deadlineEntity.addProperty({
        info: { name: 'priority', displayName: 'Priority', description: 'Deadline priority level' },
        type: 'string',
        required: true,
        schema: {
            enum: ['low', 'medium', 'high', 'critical'],
        },
    });
    addCustomStatusField(deadlineEntity, ['pending', 'completed', 'missed', 'extended'], {
        displayName: 'Deadline Status',
        description: 'Current status of the deadline',
    });
    addCreatedAtField(deadlineEntity, { description: 'When the deadline was created' });
    // Deadline-Case Association (Many-to-One)
    deadlineEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this deadline' },
        required: true,
        multiple: false,
    });
    //
    // 6. BILLING & ACCOUNTING NAMESPACE
    //
    const billingAccounting = domain.addNamespace({
        info: {
            name: 'BillingAccounting',
            displayName: 'Billing & Accounting',
            description: 'Invoicing, payments, and trust accounts',
        },
    });
    // Billing Model
    const billingModel = billingAccounting.addModel({
        info: {
            name: 'Billing',
            displayName: 'Billing & Accounting',
            description: 'Billing and accounting management',
        },
    });
    // Invoice Entity
    const invoiceEntity = billingModel.addEntity({
        info: {
            name: 'invoice',
            displayName: 'Invoice',
            description: 'Client invoice',
        },
    });
    addIdField(invoiceEntity, { displayName: 'Invoice ID', description: 'Unique identifier for the invoice' });
    addNameField(invoiceEntity, { description: 'Invoice name and description' });
    invoiceEntity.addProperty({
        info: { name: 'invoice_number', displayName: 'Invoice Number', description: 'Invoice number' },
        type: 'string',
        required: true,
        unique: true,
    });
    invoiceEntity.addProperty({
        info: { name: 'invoice_date', displayName: 'Invoice Date', description: 'Invoice date' },
        type: 'date',
        required: true,
    });
    invoiceEntity.addProperty({
        info: { name: 'due_date', displayName: 'Due Date', description: 'Invoice due date' },
        type: 'date',
        required: true,
    });
    addCurrencyAmountField(invoiceEntity, 'subtotal', 'Subtotal', {
        description: 'Invoice subtotal amount',
    });
    addCurrencyAmountField(invoiceEntity, 'tax_amount', 'Tax Amount', {
        description: 'Invoice tax amount',
    });
    addCurrencyAmountField(invoiceEntity, 'total_amount', 'Total Amount', {
        description: 'Invoice total amount',
    });
    addCustomStatusField(invoiceEntity, ['draft', 'sent', 'paid', 'overdue', 'cancelled'], {
        displayName: 'Invoice Status',
        description: 'Current status of the invoice',
    });
    addCreatedAtField(invoiceEntity, { description: 'When the invoice was created' });
    // Invoice-Client Association (Many-to-One)
    invoiceEntity.addAssociation({ key: clientEntity.key }, {
        info: { name: 'client', displayName: 'Client', description: 'Client for this invoice' },
        required: true,
        multiple: false,
    });
    // Invoice-Case Association (Many-to-One)
    invoiceEntity.addAssociation({ key: caseEntity.key }, {
        info: { name: 'case', displayName: 'Case', description: 'Case for this invoice' },
        required: false,
        multiple: false,
    });
    // Payment Entity
    const paymentEntity = billingModel.addEntity({
        info: {
            name: 'payment',
            displayName: 'Payment',
            description: 'Client payment',
        },
    });
    addIdField(paymentEntity, { displayName: 'Payment ID', description: 'Unique identifier for the payment' });
    addNameField(paymentEntity, { description: 'Payment name and description' });
    paymentEntity.addProperty({
        info: { name: 'payment_date', displayName: 'Payment Date', description: 'Payment date' },
        type: 'date',
        required: true,
    });
    paymentEntity.addProperty({
        info: { name: 'payment_method', displayName: 'Payment Method', description: 'Payment method' },
        type: 'string',
        required: true,
        schema: {
            enum: ['check', 'credit_card', 'bank_transfer', 'cash', 'online'],
        },
    });
    paymentEntity.addProperty({
        info: { name: 'reference_number', displayName: 'Reference Number', description: 'Payment reference number' },
        type: 'string',
        required: false,
    });
    addCurrencyAmountField(paymentEntity, 'amount', 'Payment Amount', {
        description: 'Payment amount',
    });
    addCustomStatusField(paymentEntity, ['pending', 'completed', 'failed', 'refunded'], {
        displayName: 'Payment Status',
        description: 'Current status of the payment',
    });
    addCreatedAtField(paymentEntity, { description: 'When the payment was created' });
    // Payment-Invoice Association (Many-to-One)
    paymentEntity.addAssociation({ key: invoiceEntity.key }, {
        info: { name: 'invoice', displayName: 'Invoice', description: 'Invoice for this payment' },
        required: true,
        multiple: false,
    });
    // Trust Account Entity
    const trustAccountEntity = billingModel.addEntity({
        info: {
            name: 'trust_account',
            displayName: 'Trust Account',
            description: 'Client trust account',
        },
    });
    addIdField(trustAccountEntity, {
        displayName: 'Trust Account ID',
        description: 'Unique identifier for the trust account',
    });
    addNameField(trustAccountEntity, { description: 'Trust account name and description' });
    trustAccountEntity.addProperty({
        info: { name: 'account_number', displayName: 'Account Number', description: 'Trust account number' },
        type: 'string',
        required: true,
        unique: true,
    });
    trustAccountEntity.addProperty({
        info: { name: 'bank_name', displayName: 'Bank Name', description: 'Bank name' },
        type: 'string',
        required: true,
    });
    addCurrencyAmountField(trustAccountEntity, 'balance', 'Account Balance', {
        description: 'Trust account balance',
    });
    addCustomStatusField(trustAccountEntity, ['active', 'inactive', 'frozen'], {
        displayName: 'Account Status',
        description: 'Current status of the trust account',
    });
    addCreatedAtField(trustAccountEntity, { description: 'When the trust account was created' });
    // TrustAccount-Client Association (Many-to-One)
    trustAccountEntity.addAssociation({ key: clientEntity.key }, {
        info: { name: 'client', displayName: 'Client', description: 'Client for this trust account' },
        required: true,
        multiple: false,
    });
    return domain;
}
//# sourceMappingURL=legal-services-domain.js.map