const mongoose = require('mongoose');

const flatTransferSettingsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    numberOfTransfers: Number,
    durationInMinutes: Number
});

const fareCodeTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    name: String,
    externalId: String,
    transitTypes: Array,
    riderTypes: Array
});

const flatFaresSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    riderType: Number,
    transitType: Number,
    mediaType: String,
    baseFare: Number
});

const zoneFaresSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    riderType: Number,
    transitType: Number,
    zonesTraveled: Number,
    mediaType: String,
    baseFare: Number
});

const fareCodesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: String,
    name: String,
    transitType: Number,
    baseFares: Array
});

const fromToStageFareCodesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    route: String,
    boardingStage: String,
    alightingStage: String,
    mediaType: String,
    fareCode: Number,
    transitType: Number
});

const fromToStageFareSettingsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    mediaType: String,
    isJourneyUpgradeAllowed: Boolean,
    journeyDuration: Number,
    extendedTicketTypeCode: Number
});

const fromToZoneFareCodesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    boardingZone: Number,
    alightingZone: Number,
    mediaType: String,
    fareCode: Number,
    transitType: Number,
    riderType: Number
});

const fromToZoneFareSettingsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    mediaType: String,
    isJourneyUpgradeAllowed: Boolean,
    journeyDuration: Number,
    extendedTicketTypeCode: Number
});

const multiPriceProductsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: Number,
    name: String,
    nameTranslations: String,
    mediaType: String,
    fareType: String,
    singleRideDuration: Number,
    journeyDuration: Number,
    timeBetweenRides: Number,
    maxNumberOfRides: Number,
    print1: String,
    print1Translations: String,
    print2: String,
    print2Translations: String,
    print3: String,
    print3Translations: String,
    sellableAccess: Array,
    adjustments: Object,
    upgrades: Object,
    deposit: Object,
    paperTicketValidityInDays: Number,
    digitalTicketValidityInDays: Number,
    validityCalculationStartCondition: String,
    returnTicketValidityInDays: Number,
    accountTypes: Array,
    smartCardProfiles: Object,
    priceRoundingType: String
});

const transitTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: Number,
    name: String
});

const riderTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: Number,
    name: String,
    type: String,
    isPerson: Boolean,
    description: String,
    iconBitmapName: String,
    isGroupFare: Boolean,
    smartCardOnly: Boolean,
    hasAccount: Boolean,
    hasSmartCard: Boolean,
    hasCash: Boolean,
    isBusinessOnly: Boolean,
    storedValue: Boolean,
    isDefault: Boolean,
    ageLimitation: Number,
    verificationRequired: Boolean,
    statusExpires: Boolean,
    canStatusBeRenewed: Boolean,
    expiryCondition: String,
    expirationDate: Date,
    nameTranslations: String,
    descriptionTranslations: String,
    iconPositions: Object,
    assignedRiderTypes: Array,
    verificationEnabledOnDeviceTypes: Array,
    verificationDocuments: Array
});

const productsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    type: String,
    externalId: Number,
    name: String,
    priceInCents: Number,
    productEntityClass: String,
    activateOn: String,
    paperTicketValidityInDays: Number,
    validityCalculationStartCondition: String,
    startDate: Date,
    endDate: Date,
    mediaType: String,
    iconBitmapName: String,
    fareMultiplier: Number,
    maximumFee: Number,
    productType: String,
    duration: Number,
    print1: String,
    print1Translations: String,
    print2: String,
    print2Translations: String,
    print3: String,
    print3Translations: String,
    print4: String,
    print4Translations: String,
    valueCredited: Number,
    minimumPrice: Number,
    maximumPrice: Number,
    discount: Number,
    sharedCode: Number,
    extendedTicketTypeCode: Number,
    sellingStartDay: Number,
    sellingEndDay: Number,
    numberOfRides: Number,
    numberOfItems: Number,
    continueDuration: Number,
    dayOfIssueUntilTime: String,
    fareCode: String,
    allowRouteSelectionOnFirstUse: Boolean,
    productRenewal: Boolean,
    renewalGroupProducts: Array,
    nameTranslations: String,
    purchasableAccess: Array,
    iconPositions: Object,
    ticketPunchSlots: Array,
    sellableAccess: Array,
    transitTypes: Array,
    zones: Array,
    adjustments: Object,
    accountTypes: Array
});

const smartCardPricesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: Number,
    name: String,
    priceInCents: Number,
    productEntityClass: String,
    replacementPrice: Number,
    minimumBalance: Number,
    maximumBalance: Number,
    depositAmount: Number,
    discountThreshold: Number,
    activationDate: Date,
    nameTranslations: String,
    purchasableAccess: Array,
    smartCardProfiles: Array
});

const functionsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    functionTypeNumber: String,
    name: String,
    type: String,
    iconBitmapName: String,
    iconPositions: Object
});

const mediaPriceAccountsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: String,
    minBalanceInCents: Number,
    maxBalanceInCents: Number,
    discountThreshold: Number,
    riderTypeExternalIds: Array,
    accountTypes: Array
});

const flatTransfersSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    riderTypeExternalId: Number,
    transferNumber: Number,
    transferPrices: Object
});

const smartCardProfilesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: String,
    cardTypeShortNumber: Number,
    cardType: String,
    cardVersionShortNumber: Number,
    cardVersion: String,
    description: String,
    expiryPeriodInDays: Number,
    artworkTypeName: String,
    artworkTypeId: Number,
    cardTechnology: String,
    settingName: String,
    settingId: Number,
    physicalCardType: String,
    mediaPurposeType: String,
    createdTimestamp: Date,
    lastChangedTimestamp: Date,
    isEnabled: Boolean,
    noOfAssignedCards: Number,
    nameTranslations: String
});

const smartCardArtworkTypesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    name: String,
    description: String,
    originalFrontsideFilename: String,
    originalBacksideFilename: String,
    createdTimestamp: Date,
    lastChangedTimestamp: Date,
    isEnabled: Boolean,
    noOfAssignedCardProfiles: Number
});

const smartCardTypeSettingsSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    name: String,
    description: String,
    originalFilename: String,
    createdTimestamp: Date,
    lastChangedTimestamp: Date,
    isEnabled: Boolean,
    noOfAssignedCardProfiles: Number
});

const vatRatesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    externalId: String,
    name: String,
    description: String,
    code: String,
    percents: Number,
    isDefault: Boolean,
    associatedProductTypes: Array
});

const vatRulesSchema = new mongoose.Schema({
    fareEnvironmentConfigurationId: String,
    paymentInstrumentType: String,
    isVatDeductedDuringTopup: Boolean
});

const FlatTransferSettings = mongoose.model('T_FlatTransferSettings', flatTransferSettingsSchema);

const FareCodeTypes = mongoose.model('T_FareCodeTypes', fareCodeTypesSchema);

const FlatFares = mongoose.model('T_FlatFares', flatFaresSchema);

const ZoneFares = mongoose.model('T_ZoneFares', zoneFaresSchema);

const FareCodes = mongoose.model('T_FareCodes', fareCodesSchema);

const FromToStageFareCodes = mongoose.model('T_FromToStageFareCodes', fromToStageFareCodesSchema);

const FromToStageFareSettings = mongoose.model('T_FromToStageFareSettings', fromToStageFareSettingsSchema);

const FromToZoneFareCodes = mongoose.model('T_FromToZoneFareCodes', fromToZoneFareCodesSchema);

const FromToZoneFareSettings = mongoose.model('T_FromToZoneFareSettings', fromToZoneFareSettingsSchema);

const MultiPriceProducts = mongoose.model('T_MultiPriceProducts', multiPriceProductsSchema);

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

const RiderTypes = mongoose.model('T_RiderTypes', riderTypesSchema);

const Products = mongoose.model('T_Products', productsSchema);

const SmartCardPrices = mongoose.model('T_SmartCardPrices', smartCardPricesSchema);

const Functions = mongoose.model('T_Functions', functionsSchema);

const MediaPriceAccounts = mongoose.model('T_MediaPriceAccounts', mediaPriceAccountsSchema);

const FlatTransfers = mongoose.model('T_FlatTransfers', flatTransfersSchema);

const SmartCardProfiles = mongoose.model('T_SmartCardProfiles', smartCardProfilesSchema);

const SmartCardArtworkTypes = mongoose.model('T_SmartCardArtworkTypes', smartCardArtworkTypesSchema);

const SmartCardTypeSettings = mongoose.model('T_SmartCardTypeSettings', smartCardTypeSettingsSchema);

const VatRates = mongoose.model('T_VatRates', vatRatesSchema);

const VatRules = mongoose.model('T_VatRules', vatRulesSchema);

module.exports = {
    FlatTransferSettings,
    FareCodeTypes,
    FlatFares,
    ZoneFares,
    FareCodes,
    FromToStageFareCodes,
    FromToStageFareSettings,
    FromToZoneFareCodes,
    FromToZoneFareSettings,
    MultiPriceProducts,
    TransitTypes,
    RiderTypes,
    Products,
    SmartCardPrices,
    Functions,
    MediaPriceAccounts,
    FlatTransfers,
    SmartCardProfiles,
    SmartCardArtworkTypes,
    SmartCardTypeSettings,
    VatRates,
    VatRules
};
