import { supabase } from '@/config/supabase';

export const teamMembershipService = {
  async getMemberships(teamId) {
    const { data, error } = await supabase
      .from('team_memberships')
      .select(`
        *,
        user:users(id, email, name)
      `)
      .eq('teamId', teamId);

    if (error) throw error;
    return data;
  },

  async createMembership(membershipData) {
    const { data, error } = await supabase
      .from('team_memberships')
      .insert([membershipData])
      .select()
      .single();

    if (error) throw error;
    return data;
  },

  async updateMembership(id, membershipData) {
    const { data, error } = await supabase
      .from('team_memberships')
      .update(membershipData)
      .eq('id', id)
      .select()
      .single();

    if (error) throw error;
    return data;
  },

  async deleteMembership(id) {
    const { error } = await supabase
      .from('team_memberships')
      .delete()
      .eq('id', id);

    if (error) throw error;
  }
};