import { Event } from '../model/event.model';
import { EventsDAO } from '../model/persistence/eventsDao';
import { CommonValidations } from './commonValidations';

const eventsDAO = new EventsDAO();
const commonValidations = new CommonValidations();

export class EventsController {

    async getEvents() : Promise<Array<Event>> {
        return await eventsDAO.getEvents();
    }

    async getEvent(eventId : number) : Promise<Event> {
        commonValidations.throwTypeErrorIfNaN(eventId);
        return await eventsDAO.getEvent(eventId);
    }

    async addEvent(json: object) : Promise<Event> {
        let event = new Event;
        event = Object.assign(event, json);

        return await eventsDAO.addEvent(event);
    }

    async deleteEvent(eventId: number) : Promise<void> {
        commonValidations.throwTypeErrorIfNaN(eventId);
        await eventsDAO.deleteEvent(eventId);
    }
}