//! Quota type - represents resource limits per project

use serde::{Deserialize, Serialize};

/// Quota represents resource limits per project
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Quota {
    /// Project ID
    pub project_id: String,
    /// Resource type
    pub resource_type: ResourceType,
    /// Maximum allowed
    pub limit: i64,
    /// Current usage
    pub current_usage: i64,
}

impl Quota {
    /// Create a new quota
    pub fn new(project_id: String, resource_type: ResourceType, limit: i64) -> Self {
        Self {
            project_id,
            resource_type,
            limit,
            current_usage: 0,
        }
    }

    /// Check if quota allows additional resources
    pub fn allows(&self, additional: i64) -> bool {
        self.current_usage + additional <= self.limit
    }

    /// Get remaining quota
    pub fn remaining(&self) -> i64 {
        self.limit - self.current_usage
    }
}

/// Resource type for quota management
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
pub enum ResourceType {
    #[default]
    VmInstance,
    VmCpu,
    VmMemoryGb,
    StorageGb,
    NetworkPort,
    LoadBalancer,
    DnsZone,
    DnsRecord,
    K8sCluster,
    K8sNode,
}

impl ResourceType {
    /// Get string representation
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::VmInstance => "vm_instance",
            Self::VmCpu => "vm_cpu",
            Self::VmMemoryGb => "vm_memory_gb",
            Self::StorageGb => "storage_gb",
            Self::NetworkPort => "network_port",
            Self::LoadBalancer => "load_balancer",
            Self::DnsZone => "dns_zone",
            Self::DnsRecord => "dns_record",
            Self::K8sCluster => "k8s_cluster",
            Self::K8sNode => "k8s_node",
        }
    }
}
