import { model, Schema, Types } from 'mongoose';
const sonarProjectSchema = new Schema({
    connectionId: Types.ObjectId,
    organization: String,
    id: String,
    key: { type: String, required: true },
    name: { type: String, required: true },
    qualifier: { type: String, required: true },
    visibility: { type: String, required: true },
    lastAnalysisDate: Date,
}, { timestamps: true });
sonarProjectSchema.index({
    connectionId: 1,
    key: 1,
});
export const SonarProjectModel = model('SonarProject', sonarProjectSchema);
const sonarMeasuresSchema = new Schema({
    sonarProjectId: Schema.Types.ObjectId,
    fetchDate: Date,
    measures: [
        {
            metric: { type: String, required: true },
            value: { type: String, required: true },
        },
    ],
});
sonarMeasuresSchema.index({
    sonarProjectId: 1,
    fetchDate: 1,
});
export const SonarMeasuresModel = model('SonarMeasures', sonarMeasuresSchema);
const sonarAlertHistorySchema = new Schema({
    collectionName: { type: String, required: true },
    project: { type: String, required: true },
    repositoryId: { type: String, required: true },
    sonarProjectId: { type: Schema.Types.ObjectId, required: true },
    date: { type: Date, required: true },
    value: { type: String, required: true },
});
sonarAlertHistorySchema.index({
    collectionName: 1,
    project: 1,
    sonarProjectId: 1,
});
export const SonarAlertHistoryModel = model('SonarAlertHistory', sonarAlertHistorySchema);
const sonarQualityGateUsedSchema = new Schema({
    collectionName: { type: String, required: true },
    project: { type: String, required: true },
    repositoryId: { type: String, required: true },
    sonarProjectId: { type: Schema.Types.ObjectId, required: true },
    name: { type: String, required: true },
    id: { type: String, required: true },
    default: { type: Boolean },
    updatedAt: { type: Date, requred: true },
});
sonarQualityGateUsedSchema.index({
    collectionName: 1,
    project: 1,
    repositoryId: 1,
});
export const SonarQualityGateUsedModel = model('SonarQualityGateUsed', sonarQualityGateUsedSchema);
const sonarProjectsForRepoSchema = new Schema({
    collectionName: { type: String, required: true },
    project: { type: String, required: true },
    repositoryId: { type: String, required: true },
    sonarProjectIds: [{ type: Schema.Types.ObjectId, required: true }],
});
sonarProjectsForRepoSchema.index({
    collectionName: 1,
    project: 1,
    repositoryId: 1,
});
export const SonarProjectsForRepoModel = model('SonarProjectsForRepo', sonarProjectsForRepoSchema);
