"""Paste-property sub-model."""

from __future__ import annotations

from typing import Optional

from torch import Tensor, nn

from ..missing_features import MissingFeatureEncoder
from ..schema import DEFAULT_SCHEMA, SchemaSpec
from .outputs import transform_paste_outputs


class PasteSubModel(nn.Module):
    """Predict paste tensile, modulus, fracture-energy and porosity channels."""

    def __init__(
        self,
        schema: SchemaSpec = DEFAULT_SCHEMA,
        hidden_dim: int = 64,
        input_dim: int = 27,
    ):
        super().__init__()
        self.schema = schema
        self.input_dim = input_dim
        self.encoder = MissingFeatureEncoder(input_dim, hidden_dim)
        self.body = nn.Sequential(
            nn.Linear(hidden_dim, hidden_dim),
            nn.SiLU(),
            nn.Linear(hidden_dim, hidden_dim),
            nn.SiLU(),
        )
        self.head = nn.Linear(hidden_dim, 4)

    def forward(self, x: Tensor, mask: Optional[Tensor] = None) -> Tensor:
        h = self.encoder(x, mask)
        h = self.body(h)
        return transform_paste_outputs(self.head(h))
