To solve this optimization problem, we will first define the decision variables and then formulate the objective function and constraints based on the given information.

Let's denote:
- $Q$ as the number of queen-sized mattresses produced.
- $K$ as the number of king-sized mattresses produced.

The profit per queen mattress is $300, and the profit per king mattress is $500. Thus, the total profit (which we aim to maximize) can be represented by the objective function:
\[ \text{Maximize:} \quad 300Q + 500K \]

There are two main constraints based on the available resources:
1. **Foam Availability Constraint**: Queen size mattresses require 20 units of foam, and king size mattresses require 30 units of foam. The company has 5000 units of foam available.
\[ 20Q + 30K \leq 5000 \]

2. **Packaging Time Constraint**: Queen size mattresses take 10 minutes to package, and king size mattresses take 15 minutes to package. The company has 2500 minutes of packaging time available.
\[ 10Q + 15K \leq 2500 \]

Additionally, we have non-negativity constraints since the number of mattresses cannot be negative:
\[ Q \geq 0 \]
\[ K \geq 0 \]

Now, let's translate this problem into Gurobi code in Python:

```python
from gurobipy import *

# Create a new model
model = Model("Mattress_Optimization")

# Define the decision variables
Q = model.addVar(vtype=GRB.CONTINUOUS, name="Queen_Mattresses", lb=0)
K = model.addVar(vtype=GRB.CONTINUOUS, name="King_Mattresses", lb=0)

# Set the objective function: Maximize profit
model.setObjective(300*Q + 500*K, GRB.MAXIMIZE)

# Add constraints
model.addConstr(20*Q + 30*K <= 5000, name="Foam_Availability")
model.addConstr(10*Q + 15*K <= 2500, name="Packaging_Time")

# Optimize the model
model.optimize()

# Print the results
if model.status == GRB.OPTIMAL:
    print(f"Optimal solution found.")
    print(f"Number of Queen Mattresses: {Q.x}")
    print(f"Number of King Mattresses: {K.x}")
    print(f"Maximum Profit: ${300*Q.x + 500*K.x:.2f}")
else:
    print("No optimal solution found. The model is likely infeasible.")
```