import type {Space} from "@/models/space";
import api from "@/network/axiosSetup"
import {User} from "@/models/user";

// async function getSpaces(): Promise<Space[]> {
//     const response = await api.get("/api/spaces");
//     if (!response.status.toString().startsWith('2')) throw new Error("Failed to fetch spaces");
//     return response.data;
// }


 async function fetchSpaces(): Promise<Space[]> {
    let spaces: Space[] = [];
    for (let i = 0; i < 10; i++) {
        spaces.push(
            {
                id: i,
                name: `Space ${i}`,
                owner: {
                    id: i,
                    username: `user_name_${i}`,
                    firstName: `user_name_${i}`,
                } as User,
                participants: [{
                    id: i,
                    username: `user_name_${i}`,
                    firstName: `user_name_${i}`,
                } as User],
                createdBy: {
                    id: i,
                    username: `user_name_${i}`,
                    firstName: `user_name_${i}`,
                } as User,
                createdAt: new Date(),
            } as Space
        )
    }
    return spaces;

}
async function fetchSpace(spaceId: number): Promise<Space> {
     return   {
         id: spaceId,
         name: `Space ${spaceId}`,
         owner: {
             id: spaceId,
             username: `user_name_${spaceId}`,
             firstName: `user_name_${spaceId}`,
         } as User,
         participants: [{
             id: spaceId,
             username: `user_name_${spaceId}`,
             firstName: `user_name_${spaceId}`,
         } as User],
         createdBy: {
             id: spaceId,
             username: `user_name_${spaceId}`,
             firstName: `user_name_${spaceId}`,
         } as User,
         createdAt: new Date(),
     } as Space
}

export const spaceService = {
    fetchSpaces, fetchSpace
};