# coding: utf-8

"""
Wallee AG Python SDK

This library allows to interact with the Wallee AG payment service.

Copyright owner: Wallee AG
Website: https://en.wallee.com
Developer email: ecosystem-team@wallee.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""


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

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from wallee.models.facade_user_friendly_query_status_model import FacadeUserFriendlyQueryStatusModel
from typing import Optional, Set
from typing_extensions import Self

class SubmittedAnalyticsQueryExecution(BaseModel):
    """
    SubmittedAnalyticsQueryExecution
    """ # noqa: E501
    query_external_id: Optional[StrictStr] = Field(default=None, description="The external id associated with this query, if any.", alias="queryExternalId")
    account_id: Optional[StrictInt] = Field(default=None, description="The ID of the target account for which the analytics query will be executed, determining the data scope for the request.", alias="accountId")
    total_billed_execution_time_ms: Optional[StrictInt] = Field(default=None, description="The total execution time, in milliseconds, that has been billed for the query.", alias="totalBilledExecutionTimeMs")
    created_timestamp: Optional[datetime] = Field(default=None, description="The date and time when the query was created.", alias="createdTimestamp")
    download_requests: Optional[StrictInt] = Field(default=None, description="The number of times the query result file has been downloaded.", alias="downloadRequests")
    original_query: Optional[StrictStr] = Field(default=None, description="The SQL query as originally submitted by the user.", alias="originalQuery")
    scanned_bytes: Optional[StrictInt] = Field(default=None, description="The total bytes of data scanned by the submitted query.", alias="scannedBytes")
    portal_query_token: Optional[StrictStr] = Field(default=None, description="The unique query token associated with the analytics query execution.", alias="portalQueryToken")
    result_file_bytes: Optional[StrictInt] = Field(default=None, description="The size, in bytes, of the result file generated by the query.", alias="resultFileBytes")
    status: Optional[FacadeUserFriendlyQueryStatusModel] = None
    __properties: ClassVar[List[str]] = ["queryExternalId", "accountId", "totalBilledExecutionTimeMs", "createdTimestamp", "downloadRequests", "originalQuery", "scannedBytes", "portalQueryToken", "resultFileBytes", "status"]

    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 SubmittedAnalyticsQueryExecution 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "query_external_id",
            "account_id",
            "total_billed_execution_time_ms",
            "created_timestamp",
            "download_requests",
            "original_query",
            "scanned_bytes",
            "portal_query_token",
            "result_file_bytes",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "queryExternalId": obj.get("queryExternalId"),
            "accountId": obj.get("accountId"),
            "totalBilledExecutionTimeMs": obj.get("totalBilledExecutionTimeMs"),
            "createdTimestamp": obj.get("createdTimestamp"),
            "downloadRequests": obj.get("downloadRequests"),
            "originalQuery": obj.get("originalQuery"),
            "scannedBytes": obj.get("scannedBytes"),
            "portalQueryToken": obj.get("portalQueryToken"),
            "resultFileBytes": obj.get("resultFileBytes"),
            "status": obj.get("status")
        })
        return _obj


