import { IGenericMediaPlayback } from "../../../../generic/types";
import { IRWCAnswerComponent } from '../../../types';
import { RWCAnswerComponent } from '../../../classes/v5';

export const transformMediaPlayback = ({ props, children }: IGenericMediaPlayback): IRWCAnswerComponent => {
    const [ startTime, startTimeTimestring, type ] = [props.value, props.label, props.rwc?.name];

    const initResult = {
        startTime,
        startTimeTimestring,
        ...props.rwc
    };

    const result = children.reduce((acc, child) => {
        const { type, props } = child;

        if (!acc[type]) acc[type] = [];
        acc[type].push(props?.rwc);

        return acc;

    }, initResult);

    return new RWCAnswerComponent(result, type);
};