import { FindPartidosParams, IPartidosAdapter, IPartido } from "./Partidos.interface";
import { Document, Model, Schema, model } from "mongoose";

export interface IPartidoDocument extends Omit<IPartido, "id">, Document {}

export class PartidosAdapterMongoose implements IPartidosAdapter {
    schema: Schema;
    partidoList: Model<IPartidoDocument>;

    constructor() {
        this.schema = new Schema({
            name: { type: String, required: true, unique: true },
            code: { type: Number, required: true, default: 0 },
            provincia: { type: String, required: true },
            latitude: { type: Number, required: true, default: 0 },
            longitude: { type: Number, required: true, default: 0 },
        });

        this.partidoList = model<IPartidoDocument>("Partido", this.schema);
    }

    public async find(filters: FindPartidosParams): Promise<IPartido[]> {
        return this.partidoList.find(filters).exec();
    }
}
