"""MySQL external data-source adapter."""

from app.core.data_source.adapters.base import BaseDataSourceAdapter


class MySQLAdapter(BaseDataSourceAdapter):
    database_type = "mysql"
    drivername = "mysql+pymysql"
    allowed_tls_options = frozenset({"ssl_ca", "ssl_cert", "ssl_key"})
    certificate_options = allowed_tls_options

    def connect_args(self, definition, credential, query_timeout):
        timeout = int(query_timeout)
        options = {
            "connect_timeout": 5,
            "read_timeout": timeout,
            "write_timeout": timeout,
            "charset": "utf8mb4",
        }
        options.update(self.validate_options(definition.tls_options))
        return options
