const mongoose = require('mongoose');

const configurationSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    name: String,
    activationDate: Date,
    creationDate: Date,
    faretableTimestamp: Date,
    distributionVersion: String,
    businessDayStart: String,
    softwareVersion: String,
    isActive: Boolean,
    isPending: Boolean
});

const transitTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: Number,
    shortNumber: Number,
    name: String,
    description: String,
    fareSystemModel: String,
    routeSystemType: String,
    nameTranslations: String,
    routes: Array,
    zones: Array
});

const zoneTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    name: String,
    externalId: Number,
    usedForPeriodPassRestriction: Boolean,
    usedForStoredValueInterchange: Boolean,
    nameTranslations: String,
    zones: Array
});

const zonesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    name: String,
    externalId: String,
    sharedCode: Number,
    shortNumber: Number,
    nameTranslations: String,
    stopsInZone: Array
});

const routesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    avlId: Number,
    externalId: String,
    name: String,
    destination: String,
    variant: String,
    direction: String,
    version: Number,
    code: String,
    codeCustomer: String,
    validFrom: Date,
    validTo: Date,
    length: Number,
    routeType: Object,
    machineId: Number,
    salesEnabled: Boolean,
    backDoorValidationEnabled: Boolean,
    stopsOnRoute: Array
});

const stopsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    machineId: Number,
    stopCode: String,
    stopName: String,
    stationCode: String,
    stopGpsLatInMillionthOfDegree: Number,
    stopGpsLonInMillionthOfDegree: Number
});

const stationsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    machineId: Number,
    stationCode: String,
    stationName: String
});

const distanceSegmentTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: String,
    name: String,
    description: String,
    divisionPointEveryInMeters: Number,
    maximumDistanceInMeters: Number,
    transitTypes: Array,
    distanceSegments: Array
});

const stageByRouteBorderAdjustmentsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    route: String,
    borderStop: String,
    lowerDistanceSegment: Number
});

const verificationDocumentsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    id: Number,
    type: String,
    isPersonal: Boolean,
    description: String,
    verificationDocumentElementIds: Array,
    typeTranslations: String,
    descriptionTranslations: String
});

const verificationDocumentElementsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    id: Number,
    name: String,
    description: String,
    type: String,
    nameTranslations: String,
    descriptionTranslations: String
});

const riderLanguagesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    languageCode: String,
    description: String,
    isDefaultLanguage: Boolean
});

const Configuration = mongoose.model('E_Configuration', configurationSchema);

const TransitTypes = mongoose.model('E_TransitTypes', transitTypesSchema);

const ZoneTypes = mongoose.model('E_ZoneTypes', zoneTypesSchema);

const Zones = mongoose.model('E_Zones', zonesSchema);

const Routes = mongoose.model('E_Routes', routesSchema);

const Stops = mongoose.model('E_Stops', stopsSchema);

const Stations = mongoose.model('E_Stations', stationsSchema);

const DistanceSegmentTypes = mongoose.model('E_DistanceSegmentTypes', distanceSegmentTypesSchema);

const StageByRouteBorderAdjustments = mongoose.model('E_StageByRouteBorderAdjustments', stageByRouteBorderAdjustmentsSchema);

const VerificationDocuments = mongoose.model('E_VerificationDocuments', verificationDocumentsSchema);

const VerificationDocumentElements = mongoose.model('E_VerificationDocumentElements', verificationDocumentElementsSchema);

const RiderLanguages = mongoose.model('E_RiderLanguages', riderLanguagesSchema);

module.exports = {
    Configuration,
    TransitTypes,
    ZoneTypes,
    Zones,
    Routes,
    Stops,
    Stations,
    DistanceSegmentTypes,
    StageByRouteBorderAdjustments,
    VerificationDocuments,
    VerificationDocumentElements,
    RiderLanguages
};
