<?php

namespace App\Http\Controllers;

use App\Models\WorkspaceMember;
use Illuminate\Http\Request;

class WorkspaceController extends Controller
{
    public function addMember(Request $request)
    {
        $request->validate([
            'workspace_id' => 'required|exists:workspaces,id',
            'user_id' => 'required|exists:users,id',
            'role_id' => 'required|exists:roles,id',
        ]);

        $member = WorkspaceMember::updateOrCreate(
            [
                'workspace_id' => $request->workspace_id,
                'user_id' => $request->user_id,
            ],
            [
                'role_id' => $request->role_id,
            ]
        );

        return response()->json([
            'status' => true,
            'message' => 'Member added successfully',
            'data' => $member
        ]);
    }
}
