# coding: utf-8

"""
    BSUB.IO API

    REST API for batch processing compute-intensive workloads.  Submit jobs, upload data, and retrieve results through a simple API. Perfect for PDF processing, video transcoding, audio transcription, and more.  ## Authentication  All endpoints require Bearer token authentication using your API key:  ``` Authorization: Bearer <your-api-key> ```  Get your API key from the [Dashboard](/).  ## Job Lifecycle  1. **Create** a job with `POST /v1/jobs` - Returns job ID and upload token 2. **Upload** data with `POST /v1/upload/{jobId}` - Uses upload token 3. **Submit** for processing with `POST /v1/jobs/{jobId}/submit` 4. **Monitor** status with `GET /v1/jobs/{jobId}` 5. **Retrieve** output with `GET /v1/jobs/{jobId}/output`  ## Job States  - `created` - Job created, awaiting data upload - `loaded` - Data uploaded successfully - `pending` - Waiting in queue for a worker - `claimed` - Worker claimed the job - `preparing` - Worker preparing to process - `processing` - Processing started - `finished` - Processing completed successfully - `failed` - Processing failed with error 

    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from uuid import UUID
from typing import Optional, Set
from typing_extensions import Self

class Job(BaseModel):
    """
    Job
    """ # noqa: E501
    id: Optional[UUID] = Field(default=None, description="Unique job identifier")
    status: Optional[StrictStr] = Field(default=None, description="Current job status")
    type: Optional[StrictStr] = Field(default=None, description="Processing type")
    user_id: Optional[StrictStr] = Field(default=None, description="User who created the job")
    upload_token: Optional[StrictStr] = Field(default=None, description="Token for uploading data (only present in `created` state)")
    data_size: Optional[StrictInt] = Field(default=None, description="Size of uploaded data in bytes")
    claimed_by: Optional[StrictStr] = Field(default=None, description="Worker ID that claimed the job")
    error_code: Optional[StrictStr] = Field(default=None, description="Error code if job failed")
    error_message: Optional[StrictStr] = Field(default=None, description="Error message if job failed")
    created_at: Optional[datetime] = Field(default=None, description="Job creation timestamp")
    updated_at: Optional[datetime] = Field(default=None, description="Last update timestamp")
    claimed_at: Optional[datetime] = Field(default=None, description="When job was claimed by worker")
    finished_at: Optional[datetime] = Field(default=None, description="When job finished (success or failure)")
    __properties: ClassVar[List[str]] = ["id", "status", "type", "user_id", "upload_token", "data_size", "claimed_by", "error_code", "error_message", "created_at", "updated_at", "claimed_at", "finished_at"]

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['created', 'loaded', 'pending', 'claimed', 'preparing', 'processing', 'finished', 'failed']):
            raise ValueError("must be one of enum values ('created', 'loaded', 'pending', 'claimed', 'preparing', 'processing', 'finished', 'failed')")
        return value

    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 Job 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,
        )
        # set to None if claimed_by (nullable) is None
        # and model_fields_set contains the field
        if self.claimed_by is None and "claimed_by" in self.model_fields_set:
            _dict['claimed_by'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "status": obj.get("status"),
            "type": obj.get("type"),
            "user_id": obj.get("user_id"),
            "upload_token": obj.get("upload_token"),
            "data_size": obj.get("data_size"),
            "claimed_by": obj.get("claimed_by"),
            "error_code": obj.get("error_code"),
            "error_message": obj.get("error_message"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "claimed_at": obj.get("claimed_at"),
            "finished_at": obj.get("finished_at")
        })
        return _obj


