input: Write a function to create an object-oriented structure to solve a maze by using Python. The function should initialize the maze with a given size, solve the maze to find the shortest path from the start (top-left corner) to the end (bottom-right corner), and return the path length. If the maze is unsolvable, return -1. The maze is represented by a 2D grid where '1' indicates a walkable path and '0' indicates an obstacle.
  
  assert solve_maze(3, 3, [[1, 0, 1], [1, 1, 1], [1, 1, 1]]) == 4
  assert solve_maze(3, 3, [[1, 0, 0], [1, 1, 0], [0, 1, 1]]) == -1
  assert solve_maze(2, 2, [[1, 0], [1, 1]]) == 2
  assert solve_maze(1, 1, [[1]]) == 0
output: def solve_maze(rows, cols, grid):
      from collections import deque
  
      directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
      queue = deque([(0, 0, 0)])
      visited = set((0, 0))
  
      while queue:
          x, y, dist = queue.popleft()
  
          if x == rows - 1 and y == cols - 1:
              return dist
  
          for dx, dy in directions:
              nx, ny = x + dx, y + dy
              if 0 <= nx < rows and 0 <= ny < cols and (nx, ny) not in visited and grid[nx][ny] == 1:
                  visited.add((nx, ny))
                  queue.append((nx, ny, dist + 1))
  
      return -1