import { TimeTrackingPolicyUser, TimeTrackingPolicyUsersDAO } from '../dataAccessObjects/policyUsers';
import { mapPolicyDAOToModel } from './timeTrackingPolicyMapper';

export const mapPolicyUserDAOToModel = (policyUserDAO: TimeTrackingPolicyUsersDAO): TimeTrackingPolicyUser => {
    return {
        fromDate: policyUserDAO.fromDate,
        id: policyUserDAO.id,
        policy: policyUserDAO.policy ? mapPolicyDAOToModel(policyUserDAO.policy) : undefined,
        policyId: policyUserDAO.policyId,
        toDate: policyUserDAO.toDate ?? undefined,
        userId: policyUserDAO.userId,
    };
};

export const mapPolicyUserModelToDAO = (policyUser: TimeTrackingPolicyUser): TimeTrackingPolicyUsersDAO => {
    const policyUserDAO = new TimeTrackingPolicyUsersDAO({
        fromDate: policyUser.fromDate,
        policyId: policyUser.policyId,
        toDate: policyUser.toDate,
        userId: policyUser.userId,
    });
    if (policyUser.id) {
        policyUserDAO.id = policyUser.id;
        policyUserDAO.isNewRecord = false;
    }
    return policyUserDAO;
};
