import { AdminService } from '@/lib/services/admin/AdminService';
import { Result } from '@/lib/contracts/Result';
import { MutationError, mapToMutationError } from '@/lib/contracts/mutations/MutationError';
import { Mutation } from '@/lib/contracts/mutations/Mutation';

/**
 * DeleteUserMutation
 *
 * Framework-agnostic mutation for deleting users.
 * Called from Server Actions.
 *
 * Input: { userId: string }
 * Output: Result<void, MutationError>
 *
 * Pattern: Server Action → Mutation → Service → API Client
 */
export class DeleteUserMutation implements Mutation<{ userId: string }, void, MutationError> {
  async execute(_input: { userId: string }): Promise<Result<void, MutationError>> {
    try {
      // Manual construction: Service creates its own dependencies
      const service = new AdminService();
      
      const result = await service.deleteUser();
      
      if (result.isErr()) {
        return Result.err(mapToMutationError(result.getError()));
      }
      
      return Result.ok(undefined);
    } catch (err) {
      return Result.err('deleteFailed');
    }
  }
}