export type Status = {
    id: number;
    name: string;
    created_at: string; // datetime as ISO string
    updated_at: string; // datetime as ISO string
    deleted?: boolean;   // tinyint, optional if nullable
};

//  @ts-ignore
const addr = import.meta.env.VITE_APIHOST;

export async function getAllStatuses(): Promise<Status[]> {
    const res = await fetch(`${addr}/status`)

    if (res.ok) {
        return res.json()
    } else {
        console.error("Something went wrong getting statuses")
    }
}

export async function assignStatus(userId: number, statusId: number, rankId: number): Promise<void> {
    const res = await fetch(`${addr}/memberStatus`, {
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify({ userId, statusId, rankId })
    })

    if (!res.ok) {
        console.error("Something went wrong assigning the status")
    }
}