import { Site } from '../../../regions/business/models/site';
import { mapSiteModelToSiteBasicDTO } from '../../../regions/presentation/mappers/mapSite';
import { TimeTrackingEntry, TimeTrackingEntryApi } from '../../business/models/timeTrackingEntry';

export const mapModelEntryToApiEntry = (
    model: TimeTrackingEntry,
    additionalData: {
        employeeId: string;
        site?: Site;
        referenceDate: string;
    },
): TimeTrackingEntryApi => {
    return {
        autoCloseFallback: model.autoCloseFallback ?? null,
        comment: model.comment,
        coordinates: model.location,
        createdAt: model.createdAt,
        date: model.time,
        employeeId: additionalData.employeeId,
        id: model.id,
        referenceDate: additionalData.referenceDate,
        site: additionalData.site ? mapSiteModelToSiteBasicDTO(additionalData.site) : undefined,
        source: model.source,
        time: model.time,
        type: model.type,
        updatedAt: model.updatedAt,
        userId: model.userId,
    };
};
