import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {IOperator} from '../../../model/entities/operator';
import {TabsComponent} from '../../../components/tabs/tabs.component';
import {Factory} from '../../../factory/factory';
import {OperatorMeetingViewComponent} from './operator-meeting-view/operator-meeting-view.component';
import {OperatorNoteViewComponent} from './operator-note-view/operator-note-view.component';
import {OperatorContactPersonViewComponent} from './operator-contact-person-view/operator-contact-person-view.component';
import {OperatorDataViewComponent} from './operator-data-view/operator-data-view.component';
import {IOperatorMeeting} from '../../../model/entities/operator-meeting';
import {IOperatorNote} from '../../../model/entities/operator-note';
import {IOperatorContact} from '../../../model/entities/operator-contact';

@Component({
  selector: 'app-operator-view',
  templateUrl: './operator-view.component.html',
  styleUrls: ['./operator-view.component.scss']
})

export class OperatorViewComponent implements OnInit {

    @Output() editOperator: EventEmitter<IOperator> = new EventEmitter<IOperator>();
    @Output() createOperatorContact: EventEmitter<IOperatorContact> = new EventEmitter<IOperatorContact>();
    @Output() editOperatorContact: EventEmitter<IOperatorContact> = new EventEmitter<IOperatorContact>();
    @Output() deleteOperatorContact: EventEmitter<number> = new EventEmitter<number>();
    @Output() createNote: EventEmitter<IOperatorNote> = new EventEmitter<IOperatorNote>();
    @Output() editNote: EventEmitter<IOperatorNote> = new EventEmitter<IOperatorNote>();
    @Output() deleteNote: EventEmitter<number> = new EventEmitter<number>();
    @Output() createMeeting: EventEmitter<IOperatorMeeting> = new EventEmitter<IOperatorMeeting>();
    @Output() editMeeting: EventEmitter<IOperatorMeeting> = new EventEmitter<IOperatorMeeting>();
    @Output() deleteMeeting: EventEmitter<number> = new EventEmitter<number>();
    @Output() editMeetingReport: EventEmitter<number> = new EventEmitter<number>();
    @Output() shortcut: EventEmitter<IOperator> = new EventEmitter<IOperator>();
    @ViewChild('tabsOperatorView', { static: true }) tabsOperatorView: TabsComponent;
    @ViewChild('operatorDataView', { static: true }) operatorDataView: OperatorDataViewComponent;
    @ViewChild('operatorContactPersonView', { static: true }) operatorContactPersonView: OperatorContactPersonViewComponent;
    @ViewChild('operatorNoteView', { static: true }) operatorNoteView: OperatorNoteViewComponent;
    @ViewChild('operatorMeetingView', { static: true }) operatorMeetingView: OperatorMeetingViewComponent;

    public operator: IOperator;

    constructor() { }

    ngOnInit() {
        this.operator = Factory.getEmptyOperator();
    }

    /**
     * Sets data
     * @param operator
     * @param isUpdate
     */
    public setData(operator: IOperator, isUpdate: boolean = false): void {
        this.operator = operator;
        this.operatorDataView.setData(this.operator);
        this.operatorContactPersonView.setData(this.operator, isUpdate);
        this.operatorNoteView.setData(this.operator, isUpdate);
        this.operatorMeetingView.setData(this.operator, isUpdate);
    }

    /**
     * Saves operator
     * @param operator
     */
    public editOperatorFunction(operator: IOperator): void {
        this.editOperator.emit(operator);
    }

    /**
     * Creates operator contact
     * @param operatorContact
     */
    public createOperatorContactFunction(operatorContact: IOperatorContact): void {
        this.createOperatorContact.emit(operatorContact);
    }

    /**
     * Edit operator contact
     * @param operatorContact
     */
    public editOperatorContactFunction(operatorContact: IOperatorContact): void {
        this.editOperatorContact.emit(operatorContact);
    }

    /**
     * Creates operator note
     * @param operatorNote
     */
    public createOperatorNoteFunction(operatorNote: IOperatorNote): void {
        this.createNote.emit(operatorNote);
    }

    /**
     * Edits note entry
     * @param operatorNote
     */
    public editOperatorNoteFunction(operatorNote: IOperatorNote) {
        this.editNote.emit(operatorNote);
    }

    /**
     * Deletes operator note
     * @param noteId
     */
    public deleteOperatorNoteFunction(noteId: number): void {
        this.deleteNote.emit(noteId);
    }

    /**
     * Deletes operator contact
     * @param operatorId
     */
    public deleteOperatorContactFunction(operatorId: number): void {
        this.deleteOperatorContact.emit(operatorId);
    }

    /**
     * Creates operator meeting
     * @param operatorMeeting
     */
    public createOperatorMeetingFunction(operatorMeeting: IOperatorMeeting): void {
        this.createMeeting.emit(operatorMeeting);
    }

    /**
     * Edits meeting entry
     * @param operatorMeeting
     */
    public editOperatorMeetingFunction(operatorMeeting: IOperatorMeeting) {
        this.editMeeting.emit(operatorMeeting);
    }

    /**
     * Deletes operator meeting
     * @param meetingId
     */
    public deleteOperatorMeetingFunction(meetingId: number): void {
        this.deleteMeeting.emit(meetingId);
    }

    /**
     * Edit report after meeting has started
     * @param reportValues
     */
    public editOperatorMeetingReportFunction(reportValues: any): void {
        this.editMeetingReport.emit(reportValues);
    }

    /**
     * Shortcut to operator detail
     * @param operator
     */
    public shortcutFunction(operator: IOperator): void {
        this.shortcut.emit(operator);
    }

}
