import { CardSchema } from "../../../client";

const DATETIME_TYPES = ["datetime", "date"];

const getAttributesFromCard = (card: CardSchema) => {
    return card.attributes.reduce(
        (values, cardAttribute) => {
            let value: boolean | number | string | null | Date = cardAttribute.value;

            if (DATETIME_TYPES.includes(cardAttribute.attribute.type.type) && value !== null) {
                value = new Date(value as string);
            }

            return {
                ...values,
                [cardAttribute.attribute.name]: value,
            };
        },
        {},
    );
};

export default getAttributesFromCard;
