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

/// License record
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct License {
    pub id: Uuid,
    pub license_key: String,
    pub status: String,
    pub owner_user_id: Uuid,
    pub server_name: Option<String>,
    pub subdomain: Option<String>,
    pub custom_domain: Option<String>,
    pub modules_enabled: Option<Vec<String>>,
    pub webstore_active: bool,
    pub webstore_subscription_id: Option<String>,
    pub created_at: DateTime<Utc>,
    pub expires_at: Option<DateTime<Utc>>,
}

/// Team member with role info
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct TeamMember {
    pub id: Uuid,
    pub license_id: Uuid,
    pub user_id: Uuid,
    pub role_id: Uuid,
    pub invited_by: Uuid,
    pub accepted_at: Option<DateTime<Utc>>,
    pub created_at: DateTime<Utc>,
}

/// Role with permissions
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct Role {
    pub id: Uuid,
    pub license_id: Option<Uuid>,
    pub role_name: String,
    pub is_system_default: bool,
    pub is_cloned_from: Option<Uuid>,
    pub permissions: serde_json::Value,
    pub created_at: DateTime<Utc>,
}

/// License activation request
#[derive(Debug, Deserialize)]
pub struct ActivateLicenseRequest {
    pub license_key: String,
    pub server_name: String,
    pub subdomain: String,
}

/// License check-in from plugin
#[derive(Debug, Deserialize)]
pub struct LicenseCheckIn {
    pub license_key: String,
    pub plugin_version: String,
}

/// License check-in response
#[derive(Debug, Serialize)]
pub struct LicenseCheckInResponse {
    pub valid: bool,
    pub status: String,
    pub modules_enabled: Vec<String>,
    pub nats_token: String,
}
