import {Models} from "node-appwrite";


export function sortByUpdateAtDesc(a: Models.Document, b: Models.Document) {
    const dateA = new Date(a.$updatedAt);
    const dateB = new Date(b.$updatedAt);

    if (dateA < dateB) {
        return 1; // Sort b before a
    } else if (dateA > dateB) {
        return -1; // Sort a before b
    } else {
        return 0; // Dates are equal
    }
}

export function sortByCreatedAtDesc(a: Models.Document, b: Models.Document) {
    const dateA = new Date(a.$createdAt);
    const dateB = new Date(b.$createdAt);

    if (dateA < dateB) {
        return 1;
    } else if (dateA > dateB) {
        return -1;
    } else {
        return 0;
    }
}

export function sortByCreatedAtAsc(a: Models.Document, b: Models.Document) {
    const dateA = new Date(a.$createdAt);
    const dateB = new Date(b.$createdAt);

    if (dateA > dateB) {
        return 1;
    } else if (dateA < dateB) {
        return -1;
    } else {
        return 0;
    }
}