# coding: utf-8

"""
    Lance Namespace Specification

    This OpenAPI specification is a part of the Lance namespace specification. It contains 2 parts:  The `components/schemas`, `components/responses`, `components/examples`, `tags` sections define the request and response shape for each operation in a Lance Namespace across all implementations. See https://lance.org/format/namespace/operations for more details.  The `servers`, `security`, `paths`, `components/parameters` sections are for the Lance REST Namespace implementation, which defines a complete REST server that can work with Lance datasets. See https://lance.org/format/namespace/rest for more details. 

    The version of the OpenAPI document: 1.0.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from lance_namespace_urllib3_client.models.identity import Identity
from typing import Optional, Set
from typing_extensions import Self

class AlterTableBackfillColumnsRequest(BaseModel):
    """
    AlterTableBackfillColumnsRequest
    """ # noqa: E501
    identity: Optional[Identity] = None
    context: Optional[Dict[str, StrictStr]] = Field(default=None, description="Arbitrary context as key-value pairs. How to use the context is custom to the specific implementation.  On a request, it carries caller-provided context to the implementation. On a response, it carries implementation-provided context back to the caller.  REST NAMESPACE ONLY Context entries are mapped to and from HTTP headers using the `header.` prefix: - On a request, any entry whose key starts with `header.` is sent as an HTTP   request header with the prefix stripped. For example, the entry   `{\"header.Authorization\": \"Bearer abc\"}` is sent as the request header   `Authorization: Bearer abc`. - On a response, every HTTP response header is returned as an entry whose key is the   header name prefixed with `header.`. For example, the response header   `x-request-id: abc123` is returned as the entry `{\"header.x-request-id\": \"abc123\"}`. ")
    id: Optional[List[StrictStr]] = Field(default=None, description="Table identifier path (namespace + table name)")
    branch: Optional[StrictStr] = Field(default=None, description="Branch to target. When not specified, the main branch is used. ")
    column: Annotated[str, Field(min_length=1, strict=True)] = Field(description="Lance field path to backfill. Nested fields use dot-separated segments; use backtick-quoted segments for literal dots and double backticks inside quoted segments. Use canonical full paths for display and errors; leaf names alone only identify top-level fields; invalid or unresolved paths should return InvalidInput or TableColumnNotFound.")
    where: Optional[StrictStr] = Field(default=None, description="Optional WHERE clause filter")
    concurrency: Optional[StrictInt] = Field(default=None, description="Optional concurrency override")
    intra_applier_concurrency: Optional[StrictInt] = Field(default=None, description="Optional intra-applier concurrency override")
    min_checkpoint_size: Optional[StrictInt] = Field(default=None, description="Optional minimum checkpoint size")
    max_checkpoint_size: Optional[StrictInt] = Field(default=None, description="Optional maximum checkpoint size")
    batch_checkpoint_flush_interval_seconds: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Optional batch checkpoint flush interval in seconds")
    read_version: Optional[StrictInt] = Field(default=None, description="Optional table version to read from")
    task_size: Optional[StrictInt] = Field(default=None, description="Optional task size")
    num_frags: Optional[StrictInt] = Field(default=None, description="Optional number of fragments")
    checkpoint_size: Optional[StrictInt] = Field(default=None, description="Optional checkpoint size")
    commit_granularity: Optional[StrictInt] = Field(default=None, description="Optional commit granularity")
    cluster: Optional[StrictStr] = Field(default=None, description="Optional cluster name")
    manifest: Optional[StrictStr] = Field(default=None, description="Optional manifest name")
    __properties: ClassVar[List[str]] = ["identity", "context", "id", "branch", "column", "where", "concurrency", "intra_applier_concurrency", "min_checkpoint_size", "max_checkpoint_size", "batch_checkpoint_flush_interval_seconds", "read_version", "task_size", "num_frags", "checkpoint_size", "commit_granularity", "cluster", "manifest"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of AlterTableBackfillColumnsRequest from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of identity
        if self.identity:
            _dict['identity'] = self.identity.to_dict()
        # set to None if where (nullable) is None
        # and model_fields_set contains the field
        if self.where is None and "where" in self.model_fields_set:
            _dict['where'] = None

        # set to None if concurrency (nullable) is None
        # and model_fields_set contains the field
        if self.concurrency is None and "concurrency" in self.model_fields_set:
            _dict['concurrency'] = None

        # set to None if intra_applier_concurrency (nullable) is None
        # and model_fields_set contains the field
        if self.intra_applier_concurrency is None and "intra_applier_concurrency" in self.model_fields_set:
            _dict['intra_applier_concurrency'] = None

        # set to None if min_checkpoint_size (nullable) is None
        # and model_fields_set contains the field
        if self.min_checkpoint_size is None and "min_checkpoint_size" in self.model_fields_set:
            _dict['min_checkpoint_size'] = None

        # set to None if max_checkpoint_size (nullable) is None
        # and model_fields_set contains the field
        if self.max_checkpoint_size is None and "max_checkpoint_size" in self.model_fields_set:
            _dict['max_checkpoint_size'] = None

        # set to None if batch_checkpoint_flush_interval_seconds (nullable) is None
        # and model_fields_set contains the field
        if self.batch_checkpoint_flush_interval_seconds is None and "batch_checkpoint_flush_interval_seconds" in self.model_fields_set:
            _dict['batch_checkpoint_flush_interval_seconds'] = None

        # set to None if read_version (nullable) is None
        # and model_fields_set contains the field
        if self.read_version is None and "read_version" in self.model_fields_set:
            _dict['read_version'] = None

        # set to None if task_size (nullable) is None
        # and model_fields_set contains the field
        if self.task_size is None and "task_size" in self.model_fields_set:
            _dict['task_size'] = None

        # set to None if num_frags (nullable) is None
        # and model_fields_set contains the field
        if self.num_frags is None and "num_frags" in self.model_fields_set:
            _dict['num_frags'] = None

        # set to None if checkpoint_size (nullable) is None
        # and model_fields_set contains the field
        if self.checkpoint_size is None and "checkpoint_size" in self.model_fields_set:
            _dict['checkpoint_size'] = None

        # set to None if commit_granularity (nullable) is None
        # and model_fields_set contains the field
        if self.commit_granularity is None and "commit_granularity" in self.model_fields_set:
            _dict['commit_granularity'] = None

        # set to None if cluster (nullable) is None
        # and model_fields_set contains the field
        if self.cluster is None and "cluster" in self.model_fields_set:
            _dict['cluster'] = None

        # set to None if manifest (nullable) is None
        # and model_fields_set contains the field
        if self.manifest is None and "manifest" in self.model_fields_set:
            _dict['manifest'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AlterTableBackfillColumnsRequest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "identity": Identity.from_dict(obj["identity"]) if obj.get("identity") is not None else None,
            "context": obj.get("context"),
            "id": obj.get("id"),
            "branch": obj.get("branch"),
            "column": obj.get("column"),
            "where": obj.get("where"),
            "concurrency": obj.get("concurrency"),
            "intra_applier_concurrency": obj.get("intra_applier_concurrency"),
            "min_checkpoint_size": obj.get("min_checkpoint_size"),
            "max_checkpoint_size": obj.get("max_checkpoint_size"),
            "batch_checkpoint_flush_interval_seconds": obj.get("batch_checkpoint_flush_interval_seconds"),
            "read_version": obj.get("read_version"),
            "task_size": obj.get("task_size"),
            "num_frags": obj.get("num_frags"),
            "checkpoint_size": obj.get("checkpoint_size"),
            "commit_granularity": obj.get("commit_granularity"),
            "cluster": obj.get("cluster"),
            "manifest": obj.get("manifest")
        })
        return _obj


