
import {User} from "@/models/user";
import {RecurrentOperation} from "@/models/recurrent-operation";
import {categoriesService} from "@/services/categories-service";

async function fetchRecurrents(spaceId: number): Promise<RecurrentOperation[]> {
    let recurrents : RecurrentOperation[] = []
    for (let i = 0; i < 10; i++) {
        recurrents.push({
            id: i,
            category: await categoriesService.fetchCategory(1,1),
            name: `Recurrent ${i}`,
            amount: Math.floor(Math.random() * 1000000),
            date: Math.floor(Math.random() * 31),
            createdBy: {
                id: 1,
                username: `username_${i}`,
                firstName: `firstName ${i}`,
            } as User,
            createdAt: Date.now(),
        } as RecurrentOperation)
    }
    return recurrents;
}

async function fetchRecurrent(spaceId: number, categoryId: number): Promise<RecurrentOperation> {
   return  {
       id: 1,
       category: await categoriesService.fetchCategory(1,1),
       name: `Recurrent ${1}`,
       amount: Math.floor(Math.random() * 1000000),
       date: Math.floor(Math.random() * 31),
       createdBy: {
           id: 1,
           username: `username_${1}`,
           firstName: `firstName ${1}`,
       } as User,
       createdAt: Date.now(),
   } as RecurrentOperation
}

export const recurrentsService  = {
    fetchRecurrents, fetchRecurrent
}