import { model, Schema } from 'mongoose';
const releaseSchema = new Schema({
    collectionName: { type: String, required: true },
    project: { type: String, required: true },
    id: { type: Number, required: true },
    name: { type: String, required: true },
    status: { type: String, required: true },
    createdOn: { type: Date, required: true },
    modifiedOn: { type: Date, required: true },
    createdById: { type: String, required: true },
    modifiedById: { type: String, required: true },
    environments: [
        {
            id: { type: Number, required: true },
            releaseId: { type: Number, required: true },
            name: { type: String, required: true },
            status: { type: String, required: true },
            deploySteps: [
                {
                    id: { type: Number, required: true },
                    deploymentId: { type: Number, required: true },
                    attempt: { type: Number, required: true },
                    reason: { type: String, required: true },
                    status: { type: String, required: true },
                    operationStatus: { type: String, required: true },
                    requestedById: { type: String, required: true },
                    requestedForId: { type: String, required: true },
                    queuedOn: { type: Date, required: true },
                    lastModifiedById: { type: String, required: true },
                    lastModifiedOn: { type: Date, required: true },
                    hasStarted: { type: Boolean, required: true },
                },
            ],
            rank: { type: Number, required: true },
            definitionEnvironmentId: { type: Number, required: true },
            conditions: [
                {
                    conditionType: { type: String, required: true },
                    name: { type: String, required: true },
                    value: { type: String, required: true },
                },
            ],
        },
    ],
    artifacts: [
        {
            sourceId: { type: String, required: true },
            type: { type: String, required: true },
            alias: { type: String, required: true },
            isPrimary: { type: Boolean, required: true },
            definition: {
                isTriggeringArtifact: { type: Boolean },
                buildPipelineUrl: { type: String },
                buildUri: { type: String },
                buildDefinitionId: { type: Number },
                branch: { type: String },
                pullRequestId: { type: String },
                pullRequestSourceBranch: { type: String },
                pullRequestSourceBranchCommitId: { type: String },
                pullRequestMergeCommitId: { type: String },
                pullRequestTargetBranch: { type: String },
                requestedForId: { type: String },
                repositoryId: { type: String },
                repositoryName: { type: String },
                connectionId: { type: String },
                connectionName: { type: String },
            },
        },
    ],
    releaseDefinitionRevision: { type: Number, required: true },
    releaseDefinitionId: { type: Number, required: true },
    releaseDefinitionName: { type: String, required: true },
    releaseDefinitionUrl: { type: String, required: true },
    description: { type: String },
    reason: { type: String, required: true },
    releaseNameFormat: { type: String, required: true },
    keepForever: { type: Boolean, required: true },
    definitionSnapshotRevision: { type: Number, required: true },
    logsContainerUrl: { type: String, required: true },
    url: { type: String, required: true },
});
releaseSchema.index({ collectionName: 1, project: 1, id: 1 });
releaseSchema.index({ collectionName: 1, project: 1, releaseDefinitionId: 1 });
export const ReleaseModel = model('Release', releaseSchema);
