const mongoose = require('mongoose');
const { Schema } = mongoose;

const gameSchema = new Schema({
  leagueId: { type: Number, required: true },
  eventId: { type: Number, required: true },
  leagueName: { type: String, required: true },
  teamHomeName: { type: String, required: true },
  teamAwayName: { type: String, required: true },
  timestamp: { type: Number, required: true }
}, { _id: false });

const relSchema = new Schema({
  jc: { type: gameSchema },
  ps: { type: gameSchema },
  ob: { type: gameSchema },
}, { _id: false });

const relationSchema = new Schema({
  id: { type: Number, required: true },
  rel: { type: relSchema, required: true },
}, {
  toJSON: {
    transform(doc, ret) {
      delete ret._id;
      delete ret.__v;
    }
  },
  toObject: {
    transform(doc, ret) {
      delete ret._id;
      delete ret.__v;
    }
  }
});

module.exports = mongoose.model('Relation', relationSchema);