//! {{RESOURCE_NAME_PASCAL}} entity
//!
//! Generated by: keg gen api {{RESOURCE_NAME}}
//!
//! Represents a database row. Used by the repository and logic layers.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// Main entity struct — matches the database table
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct {{RESOURCE_NAME_PASCAL}} {
    pub id: Uuid,
    pub name: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

/// Data Transfer Object for creating a new entity
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Create{{RESOURCE_NAME_PASCAL}} {
    pub name: String,
}

/// Data Transfer Object for updating an existing entity
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Update{{RESOURCE_NAME_PASCAL}} {
    pub name: Option<String>,
}

impl {{RESOURCE_NAME_PASCAL}} {
    /// Create a new entity with generated ID and timestamps
    pub fn new(name: String) -> Self {
        let now = Utc::now();
        Self {
            id: Uuid::new_v4(),
            name,
            created_at: now,
            updated_at: now,
        }
    }

    /// Apply an update to the entity
    pub fn apply_update(&mut self, update: Update{{RESOURCE_NAME_PASCAL}}) {
        if let Some(name) = update.name {
            self.name = name;
        }
        self.updated_at = Utc::now();
    }
}