
    ȴh!                        S r SSKrSSKJr  SSKJr  SSKJr   " S S\R                  5      r	 " S S	\R                  5      r
 " S
 S\R                  5      r " S S\R                  5      r " S S\R                  5      rg)a"  
Core Models for Stream Processor Application

This module contains abstract base models and shared functionality
that is used across multiple applications in the Stream Processor project.
These models provide common fields and methods that promote consistency
and reduce code duplication.
    N)models)timezone)Userc                      ^  \ rS rSrSr\R                  " SSS9r\R                  " SSS9r " S S	5      r	U 4S
 jr
SrU =r$ )TimestampedModel   aw  
Abstract base model that provides timestamp fields.

This model adds created_at and updated_at fields to any model
that inherits from it. These fields are automatically managed
and provide audit trail capabilities.

Attributes:
    created_at (DateTimeField): Timestamp when the record was created
    updated_at (DateTimeField): Timestamp when the record was last modified
Tz&Timestamp when this record was created)auto_now_add	help_textz,Timestamp when this record was last modified)auto_nowr
   c                       \ rS rSrSrSrg)TimestampedModel.Meta)   T N__name__
__module____qualname____firstlineno__abstract__static_attributes__r       <C:\Users\brahi\OneDrive\Desktop\Code\src\apps\core\models.pyMetar   )       r   r   c                 Z   > [         R                  " 5       U l        [        TU ]  " U0 UD6  g)aj  
Override save method to ensure updated_at is always current.

This method ensures that the updated_at field is always set
to the current timestamp when a record is saved, regardless
of whether it's a new record or an update.

Args:
    *args: Variable length argument list for parent save method
    **kwargs: Arbitrary keyword arguments for parent save method
N)r   now
updated_atsupersave)selfargskwargs	__class__s      r   r   TimestampedModel.save-   s#     #,,.d%f%r   )r   )r   r   r   r   __doc__r   DateTimeField
created_atr   r   r   r   __classcell__)r#   s   @r   r   r      sL    
 %%:J %%@J
 & &r   r   c                   f    \ rS rSrSr\R                  " S\R                  SSS9r	 " S S5      r
S	rg
)	UUIDModel?   a1  
Abstract base model that provides UUID primary key.

This model uses UUID as the primary key instead of the default
auto-incrementing integer. UUIDs are useful for distributed systems
and provide better security by making IDs unpredictable.

Attributes:
    id (UUIDField): Primary key using UUID format
TFz!Unique identifier for this record)primary_keydefaulteditabler
   c                       \ rS rSrSrSrg)UUIDModel.MetaS   Tr   Nr   r   r   r   r   r0   S   r   r   r   r   N)r   r   r   r   r%   r   	UUIDFielduuiduuid4idr   r   r   r   r   r*   r*   ?   s3    	 
		

5	
B r   r*   c                   l    \ rS rSrSr\R                  " \\R                  SSS9r	 " S S5      r
S rS	rg
)UserOwnedModelX   a@  
Abstract base model for records that belong to a specific user.

This model adds a foreign key relationship to the User model,
allowing records to be associated with specific users. It also
provides utility methods for checking ownership.

Attributes:
    owner (ForeignKey): Reference to the User who owns this record
z%(class)s_setzUser who owns this record)	on_deleterelated_namer
   c                       \ rS rSrSrSrg)UserOwnedModel.Metal   Tr   Nr   r   r   r   r   r<   l   r   r   r   c                      U R                   U:H  $ )a-  
Check if this record is owned by the specified user.

This method provides a convenient way to check ownership
of a record, which is useful for permission checking.

Args:
    user (User): The user to check ownership against
    
Returns:
    bool: True if the user owns this record, False otherwise
)owner)r    users     r   is_owned_byUserOwnedModel.is_owned_byp   s     zzT!!r   r   N)r   r   r   r   r%   r   
ForeignKeyr   CASCADEr?   r   rA   r   r   r   r   r7   r7   X   s8    	 ..$-	E "r   r7   c                   t    \ rS rSrSr/ SQr\R                  " S\SSSS9r " S	 S
5      r	S r
S rS rS rSrg)StatusModel   z
Abstract base model that provides status tracking.

This model adds status field with common status choices
that can be used across different types of records.

Attributes:
    status (CharField): Current status of the record
))activeActive)inactiveInactive)pendingPending)
processing
Processing)	completed	Completed)failedFailed)	cancelled	Cancelled   rL   TzCurrent status of this record)
max_lengthchoicesr-   db_indexr
   c                       \ rS rSrSrSrg)StatusModel.Meta   Tr   Nr   r   r   r   r   r[      r   r   r   c                      U R                   S:H  $ )zl
Check if this record has an active status.

Returns:
    bool: True if status is 'active', False otherwise
rH   statusr    s    r   	is_activeStatusModel.is_active        {{h&&r   c                      U R                   S:H  $ )zx
Check if this record is currently being processed.

Returns:
    bool: True if status is 'processing', False otherwise
rN   r^   r`   s    r   is_processingStatusModel.is_processing   s     {{l**r   c                      U R                   S:H  $ )zs
Check if this record has completed processing.

Returns:
    bool: True if status is 'completed', False otherwise
rP   r^   r`   s    r   is_completedStatusModel.is_completed   s     {{k))r   c                      U R                   S:H  $ )zm
Check if this record has failed processing.

Returns:
    bool: True if status is 'failed', False otherwise
rR   r^   r`   s    r   	is_failedStatusModel.is_failed   rc   r   r   N)r   r   r   r   r%   STATUS_CHOICESr   	CharFieldr_   r   ra   re   rh   rk   r   r   r   r   rF   rF      sM    N 1F '+*'r   rF   c                       \ rS rSrSr\R                  " SSSSS9r\R                  " SS9r	\R                  " SS	S
9r
\R                  " SSSS9r " S S5      rS r\SS j5       rSrg)ConfigurationModel   a  
Abstract base model for configuration records.

This model provides a structure for storing configuration
key-value pairs with metadata about when they were created
and last modified.

Attributes:
    key (CharField): Configuration key identifier
    value (TextField): Configuration value (can store JSON)
    description (TextField): Human-readable description of the setting
    is_active (BooleanField): Whether this configuration is active
d   Tz0Unique identifier for this configuration setting)rW   uniquerY   r
   z2Configuration value (can be JSON for complex data))r
   z3Description of what this configuration setting does)blankr
   z,Whether this configuration setting is active)r-   rY   r
   c                       \ rS rSrSrS/rSrg)ConfigurationModel.Meta   Tkeyr   N)r   r   r   r   r   orderingr   r   r   r   r   rv      s    7r   r   c                     U R                   $ )zj
String representation of the configuration.

Returns:
    str: Configuration key for easy identification
)rx   r`   s    r   __str__ConfigurationModel.__str__   s     xxr   Nc                      U R                   R                  USS9nUR                  $ ! U R                   a    Us $ f = f)aK  
Get configuration value by key with optional default.

This class method provides a convenient way to retrieve
configuration values with fallback to default values.

Args:
    key (str): Configuration key to look up
    default: Default value if key is not found
    
Returns:
    str: Configuration value or default if not found
T)rx   ra   )objectsgetvalueDoesNotExist)clsrx   r-   configs       r   get_config_value#ConfigurationModel.get_config_value   sA    	[[___=F<< 	N	s   %( ==r   )N)r   r   r   r   r%   r   rn   rx   	TextFieldr   descriptionBooleanFieldra   r   r{   classmethodr   r   r   r   r   rp   rp      s     

D	C FE
 ""GK ##@I   r   rp   )r%   r3   	django.dbr   django.utilsr   django.contrib.auth.modelsr   Modelr   r*   r7   rF   rp   r   r   r   <module>r      so      ! +,&v|| ,&^ 2%"V\\ %"PE'&,, E'PK Kr   