from typing import List, Optional
from dataclasses import dataclass, field
from .Attribute import Attribute

@dataclass
class selectAttribute(Attribute):
    """Class for select attributes."""
    options: List[str] = None
    
    def __post_init__(self):
        """Post-initialization to set the HTML input type."""
        self.html_input_type = "select"

    def validate(self) -> Optional[str]:
        """Validate select-specific attributes."""
        error = super().validate()
        if error:
            return error
        if not self.options:
            return f"options cannot be empty for attribute '{self.attrib_name}'."
        if self.default_val is not None and self.default_val not in self.options:
            return f"default_val must be one of the options for attribute '{self.attrib_name}'."
        return None