import { model, Schema } from 'mongoose';
const testSchema = new Schema({
    collectionName: { type: String, required: true },
    id: { type: Number, required: true },
    name: { type: String },
    url: { type: String, required: true },
    buildConfiguration: {
        id: { type: Number },
        number: { type: String },
        platform: { type: String },
        buildDefinitionId: { type: Number },
        project: {
            name: { type: String },
        },
    },
    project: {
        id: { type: String },
        name: { type: String },
    },
    startedDate: { type: Date, required: true },
    completedDate: { type: Date, required: true },
    state: { type: String },
    totalTests: { type: Number, required: true },
    revision: { type: Number },
    release: {
        id: { type: Number },
        name: { type: String },
        environmentId: { type: Number },
        environmentName: { type: String },
        definitionId: { type: Number },
        environmentDefinitionId: { type: Number },
        environmentDefinitionName: { type: String },
    },
    webAccessUrl: { type: String },
    runStatistics: [
        {
            state: { type: String },
            outcome: { type: String },
            count: { type: Number },
        },
    ],
}, { timestamps: true });
// For writes
testSchema.index({
    'collectionName': 1,
    'project.name': 1,
    'id': 1,
});
testSchema.index({
    'collectionName': 1,
    'project.name': 1,
    'buildConfiguration.buildDefinitionId': 1,
});
testSchema.index({
    'collectionName': 1,
    'project.name': 1,
    'buildConfiguration.id': 1,
});
testSchema.index({
    'collectionName': 1,
    'project.name': 1,
    'release.id': 1,
}, { sparse: true });
export const TestRunModel = model('TestRun', testSchema);
