//
// Copyright Cedar Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

syntax = "proto3";
package cedar_policy_validator;

import "core.proto";

// the protobuf Schema message describes a complete schema.
message Schema {
    repeated EntityDecl entity_decls = 1;
    repeated ActionDecl action_decls = 2;
}

// the protobuf EntityDecl message contains all of the schema's
// information about a single entity type.
message EntityDecl {
    cedar_policy_core.Name name = 1;
    repeated cedar_policy_core.Name descendants = 2;
    map<string, AttributeType> attributes = 3;
    optional Type tags = 5;
    repeated string enum_choices = 6;
}

// the protobuf ActionDecl message contains all of the schema's
// information about a single action.
message ActionDecl {
    cedar_policy_core.EntityUid name = 1;
    repeated cedar_policy_core.EntityUid descendants = 3;
    map<string, AttributeType> context = 4;
    repeated cedar_policy_core.Name principal_types = 5;
    repeated cedar_policy_core.Name resource_types = 6;
}

message Type {
    oneof data {
        // Primitive types
        Prim prim = 1;
        // Set with the specified element type
        Type set_elem = 2;
        // Entity type
        cedar_policy_core.Name entity = 3;
        // Record type
        // Map types are not allowed inside oneof, so we can't inline the map here
        Record record = 4;
        // Extension type
        cedar_policy_core.Name ext = 5;
    }

    enum Prim {
        String = 0;
        Bool = 1;
        Long = 2;
    }

    message Record {
        map<string, AttributeType> attrs = 1;
    }
}

message AttributeType {
    Type attr_type = 1;
    bool is_required = 2;
}

enum ValidationMode {
    Strict = 0;
    Permissive = 1;
    Partial = 2;
}
