/*
 * Artifact Keeper API
 *
 * REST API for Artifact Keeper, an open-source universal artifact registry. Covers user management, repositories, artifacts, search, security scanning, SBOM, dependency tracking, SSO, analytics, monitoring, telemetry, lifecycle policies, plugins, edge nodes, migration, and administration. Format-specific protocol endpoints (npm, PyPI, Maven, Docker/OCI, etc.) are not included; those follow their respective upstream specifications.
 *
 * The version of the OpenAPI document: 1.0.0-a2
 * 
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Permission {
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "resource_type")]
    pub resource_type: ResourceType,
    #[serde(rename = "resource_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub resource_id: Option<Option<uuid::Uuid>>,
    #[serde(rename = "actions")]
    pub actions: Vec<Actions>,
    #[serde(rename = "principal_type")]
    pub principal_type: PrincipalType,
    #[serde(rename = "principal_id")]
    pub principal_id: uuid::Uuid,
    #[serde(rename = "created_at")]
    pub created_at: String,
}

impl Permission {
    pub fn new(id: uuid::Uuid, name: String, resource_type: ResourceType, actions: Vec<Actions>, principal_type: PrincipalType, principal_id: uuid::Uuid, created_at: String) -> Permission {
        Permission {
            id,
            name,
            resource_type,
            resource_id: None,
            actions,
            principal_type,
            principal_id,
            created_at,
        }
    }
}
/// 
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum ResourceType {
    #[serde(rename = "repository")]
    Repository,
    #[serde(rename = "system")]
    System,
}

impl Default for ResourceType {
    fn default() -> ResourceType {
        Self::Repository
    }
}
/// 
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Actions {
    #[serde(rename = "read")]
    Read,
    #[serde(rename = "write")]
    Write,
    #[serde(rename = "delete")]
    Delete,
    #[serde(rename = "admin")]
    Admin,
}

impl Default for Actions {
    fn default() -> Actions {
        Self::Read
    }
}
/// 
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum PrincipalType {
    #[serde(rename = "user")]
    User,
    #[serde(rename = "group")]
    Group,
}

impl Default for PrincipalType {
    fn default() -> PrincipalType {
        Self::User
    }
}

