import api from './api';

export interface Batch {
    id: string;
    name: string;
    strain: string;
    startDate: string;
    harvestDate?: string;
    status: string;
    roomId?: string;
    source: 'CLONE' | 'SEED';
    stage: 'CLONE_IN' | 'VEGETATIVE' | 'FLOWERING' | 'HARVEST' | 'DRYING' | 'CURING' | 'FINISHED';
    plantCount: number;
    metrcTags?: string[];
    room?: {
        name: string;
    };
    ipmSchedule?: {
        id: string;
        nextTreatment: string;
        intervalDays: number;
        product?: string;
    };
    touchPoints?: {
        id: string;
        type: string;
        notes?: string;
        createdAt: string;
        user?: {
            id: string;
            name: string;
        };
    }[];
}

export const batchesApi = {
    getAll: async () => {
        const response = await api.get<Batch[]>('/batches');
        return response.data;
    },

    getById: async (id: string) => {
        const response = await api.get<Batch>(`/batches/${id}`);
        return response.data;
    },

    create: async (data: any) => {
        const response = await api.post<Batch>('/batches', data);
        return response.data;
    },

    update: async (id: string, data: any) => {
        const response = await api.put<Batch>(`/batches/${id}`, data);
        return response.data;
    }
};
