"""A simple PDK component with @pcell.

The `@pcell` decorator turns a function into a parametrized cell
factory. Each unique combination of non-default arguments yields a
distinct cell name automatically — distinct calls don't collide in GDS,
identical calls share the same cell definition under the hood.
"""
import lumicron as lm
import lumicron_pdk as lpdk

LAYER = lpdk.LayerTable(
    MTL1 = lpdk.Layer(4, 0, color="#ffd700", min_width=1.0, min_spacing=1.0),
)


@lm.pcell
def Pad(size: float = 80.0, layer: lm.LayerSpec = LAYER.MTL1):
    """A square electrical bond pad with one electrical port."""
    c = lm.CELL("Pad")

    body = lm.Rectangle(x_dim=size, y_dim=size, layer=layer)
    h = c.add(body)
    c.Place(h).at((0, 0))

    # Publish a port at the south edge so routes can land on it.
    c.add(lm.PORT(
        "p", position=(0, -size / 2), direction=270,
        width=size, layer=layer, port_type="electrical",
    ))
    return c


@lm.pcell
def PadDemo():
    """Two pads side-by-side at different sizes — different cell names auto-derived."""
    c = lm.CELL("PadDemo")
    p1 = c.add(Pad(size=80))
    p2 = c.add(Pad(size=120))
    c.Place(p1).at((0, 0))
    c.Place(p2).at((250, 0))
    return c


if __name__ == "__main__":
    PadDemo().to_gds("pad_demo.gds")
