///`authz` type for a resource of type RackUsed to uniquely identify a resource of type Rack across renames, moves, etc., and to do authorization checks (see  [`crate::context::OpContext::authorize()`]).  See [`crate::authz`] module-level documentation for more information.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Rack {
    parent: Fleet,
    key: ::omicron_uuid_kinds::TypedUuid<::omicron_uuid_kinds::RackKind>,
    lookup_type: LookupType,
}
impl Rack {
    /// Makes a new `authz` struct for this resource with the given
    /// `parent`, unique key `key`, looked up as described by
    /// `lookup_type`
    pub fn new(
        parent: Fleet,
        key: ::omicron_uuid_kinds::TypedUuid<::omicron_uuid_kinds::RackKind>,
        lookup_type: LookupType,
    ) -> Rack {
        Rack {
            parent,
            key: key.into(),
            lookup_type,
        }
    }
    /// A version of `new` that takes the primary key type directly.
    /// This is only different from [`Self::new`] if this resource
    /// uses a different input key type.
    pub fn with_primary_key(
        parent: Fleet,
        key: ::omicron_uuid_kinds::TypedUuid<::omicron_uuid_kinds::RackKind>,
        lookup_type: LookupType,
    ) -> Rack {
        Rack { parent, key, lookup_type }
    }
    pub fn id(&self) -> ::omicron_uuid_kinds::TypedUuid<::omicron_uuid_kinds::RackKind> {
        self.key.clone().into()
    }
    /// Describes how to register this type with Oso
    pub(super) fn init() -> Init {
        use oso::PolarClass;
        Init {
            polar_snippet: "\n                resource Rack {\n                    permissions = [\n                        \"list_children\",\n                        \"modify\",\n                        \"read\",\n                        \"create_child\",\n                    ];\n                    \n                    relations = { parent_fleet: Fleet };\n                    \"list_children\" if \"viewer\" on \"parent_fleet\";\n                    \"read\" if \"viewer\" on \"parent_fleet\";\n                    \"modify\" if \"admin\" on \"parent_fleet\";\n                    \"create_child\" if \"admin\" on \"parent_fleet\";\n                }\n                has_relation(fleet: Fleet, \"parent_fleet\", child: Rack)\n                    if child.fleet = fleet;\n            ",
            polar_class: Rack::get_polar_class(),
        }
    }
}
impl Eq for Rack {}
impl PartialEq for Rack {
    fn eq(&self, other: &Self) -> bool {
        self.key == other.key
    }
}
impl oso::PolarClass for Rack {
    fn get_polar_class_builder() -> oso::ClassBuilder<Self> {
        oso::Class::builder()
            .with_equality_check()
            .add_method(
                "has_role",
                |r: &Rack, actor: AuthenticatedActor, role: String| { false },
            )
            .add_attribute_getter("fleet", |r: &Rack| r.parent.clone())
    }
}
impl ApiResource for Rack {
    fn parent(&self) -> Option<&dyn AuthorizedResource> {
        Some(&self.parent)
    }
    fn resource_type(&self) -> ResourceType {
        ResourceType::Rack
    }
    fn lookup_type(&self) -> &LookupType {
        &self.lookup_type
    }
    fn as_resource_with_roles(&self) -> Option<&dyn ApiResourceWithRoles> {
        None
    }
}
