var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import OnCallDutyPolicySchedule from "./OnCallDutyPolicySchedule";
import Project from "./Project";
import User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import { PlanType } from "../../Types/Billing/SubscriptionPlan";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import TableBillingAccessControl from "../../Types/Database/AccessControl/TableBillingAccessControl";
import ColumnLength from "../../Types/Database/ColumnLength";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
import TableColumn from "../../Types/Database/TableColumn";
import TableColumnType from "../../Types/Database/TableColumnType";
import TableMetadata from "../../Types/Database/TableMetadata";
import TenantColumn from "../../Types/Database/TenantColumn";
import Recurring from "../../Types/Events/Recurring";
import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import RestrictionTimes from "../../Types/OnCallDutyPolicy/RestrictionTimes";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
let OnCallDutyPolicyScheduleLayer = class OnCallDutyPolicyScheduleLayer extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.onCallDutyPolicySchedule = undefined;
        this.onCallDutyPolicyScheduleId = undefined;
        this.name = undefined;
        this.description = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.order = undefined;
        this.startsAt = undefined;
        this.rotation = undefined;
        this.handOffTime = undefined;
        this.restrictionTimes = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project Resource in which this object belongs",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], OnCallDutyPolicyScheduleLayer.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of your OneUptime Project in which this object belongs",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], OnCallDutyPolicyScheduleLayer.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "onCallDutyPolicyScheduleId",
        type: TableColumnType.Entity,
        modelType: OnCallDutyPolicySchedule,
        title: "On-Call Policy Schedule",
        description: "Relation to On-Call Policy Schedule where this escalation rule belongs.",
    }),
    ManyToOne(() => {
        return OnCallDutyPolicySchedule;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "onCallDutyPolicyScheduleId" }),
    __metadata("design:type", OnCallDutyPolicySchedule)
], OnCallDutyPolicyScheduleLayer.prototype, "onCallDutyPolicySchedule", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "On-Call Policy Schedule ID",
        description: "ID of your On-Call Policy Schedule where this escalation rule belongs.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], OnCallDutyPolicyScheduleLayer.prototype, "onCallDutyPolicyScheduleId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Name",
        description: "Friendly name for this layer",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], OnCallDutyPolicyScheduleLayer.prototype, "name", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Description",
        description: "Description for this layer. This is optional and can be left blank.",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], OnCallDutyPolicyScheduleLayer.prototype, "description", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "createdByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Created by User",
        description: "Relation to User who created this object (if this object was created by a User)",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], OnCallDutyPolicyScheduleLayer.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Created by User ID",
        description: "User ID who created this object (if this object was created by a User)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], OnCallDutyPolicyScheduleLayer.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "deletedByUserId",
        type: TableColumnType.Entity,
        title: "Deleted by User",
        modelType: User,
        description: "Relation to User who deleted this object (if this object was deleted by a User)",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], OnCallDutyPolicyScheduleLayer.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Deleted by User ID",
        description: "User ID who deleted this object (if this object was deleted by a User)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], OnCallDutyPolicyScheduleLayer.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    TableColumn({
        isDefaultValueColumn: false,
        type: TableColumnType.Number,
        canReadOnRelationQuery: true,
        title: "Order",
        description: "Order / Priority of this layer. Lower the number, higher the priority.",
    }),
    Column({
        type: ColumnType.Number,
    }),
    __metadata("design:type", Number)
], OnCallDutyPolicyScheduleLayer.prototype, "order", void 0);
__decorate([
    TableColumn({
        title: "Start At",
        type: TableColumnType.Date,
        required: true,
        description: "Start date and time of this layer.",
    }),
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    Column({
        nullable: false,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], OnCallDutyPolicyScheduleLayer.prototype, "startsAt", void 0);
__decorate([
    TableColumn({
        title: "Rotation",
        type: TableColumnType.JSON,
        required: true,
        description: "How often would you like to hand off the duty to the next user in this layer?",
    }),
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    Column({
        nullable: false,
        type: ColumnType.JSON,
        default: Recurring.getDefault(),
        transformer: Recurring.getDatabaseTransformer(),
    }),
    __metadata("design:type", Recurring)
], OnCallDutyPolicyScheduleLayer.prototype, "rotation", void 0);
__decorate([
    TableColumn({
        title: "Hand Off Time",
        type: TableColumnType.Date,
        required: true,
        description: "Hand off time. When would you like to hand off the duty to the next user in this layer?",
    }),
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    Column({
        nullable: false,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], OnCallDutyPolicyScheduleLayer.prototype, "handOffTime", void 0);
__decorate([
    TableColumn({
        title: "Restriction Times",
        type: TableColumnType.JSON,
        required: true,
        description: "Restrict this layer to these times",
    }),
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    Column({
        nullable: false,
        type: ColumnType.JSON,
        default: RestrictionTimes.getDefault(),
        transformer: RestrictionTimes.getDatabaseTransformer(),
    }),
    __metadata("design:type", RestrictionTimes)
], OnCallDutyPolicyScheduleLayer.prototype, "restrictionTimes", void 0);
OnCallDutyPolicyScheduleLayer = __decorate([
    EnableDocumentation(),
    TableBillingAccessControl({
        create: PlanType.Growth,
        read: PlanType.Growth,
        update: PlanType.Growth,
        delete: PlanType.Growth,
    }),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.CreateOnCallDutyPolicyScheduleLayer,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.OnCallAdmin,
            Permission.OnCallMember,
            Permission.OnCallViewer,
            Permission.ReadOnCallDutyPolicyScheduleLayer,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteOnCallDutyPolicyScheduleLayer,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditOnCallDutyPolicyScheduleLayer,
        ],
    }),
    CrudApiEndpoint(new Route("/on-call-duty-schedule-layer")),
    TableMetadata({
        tableName: "OnCallDutyPolicyScheduleLayer",
        singularName: "On-Call Schedule Layer",
        pluralName: "On-Call Schedule Layers",
        icon: IconProp.Layers,
        tableDescription: "On-Call Schedule Layers",
    }),
    Entity({
        name: "OnCallDutyPolicyScheduleLayer",
    })
], OnCallDutyPolicyScheduleLayer);
export default OnCallDutyPolicyScheduleLayer;
//# sourceMappingURL=OnCallDutyPolicyScheduleLayer.js.map