# generated by datamodel-codegen:
#   filename:  OpenLineage.json
#   timestamp: 2023-10-13T22:13:47+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Dict, List, Optional
from uuid import UUID

from pydantic import AnyUrl, BaseModel, Extra, Field


class EventType(Enum):
    START = "START"
    RUNNING = "RUNNING"
    COMPLETE = "COMPLETE"
    ABORT = "ABORT"
    FAIL = "FAIL"
    OTHER = "OTHER"


class BaseFacet(BaseModel):
    class Config:
        extra = Extra.allow

    field_producer: AnyUrl = Field(
        ...,
        alias="_producer",
        description="URI identifying the producer of this metadata. For example this could be a git url with a given tag or sha",
        example="https://github.com/OpenLineage/OpenLineage/blob/v1-0-0/client",
    )
    field_schemaURL: AnyUrl = Field(
        ...,
        alias="_schemaURL",
        description="The JSON Pointer (https://tools.ietf.org/html/rfc6901) URL to the corresponding version of the schema definition for this facet",
        example="https://openlineage.io/spec/1-0-2/OpenLineage.json#/$defs/BaseFacet",
    )


class DatasetFacet(BaseFacet):
    pass


class Dataset(BaseModel):
    namespace: str = Field(..., description="The namespace containing that dataset", example="my-datasource-namespace")
    name: str = Field(
        ..., description="The unique name for that dataset within that namespace", example="instance.schema.table"
    )
    facets: Optional[Dict[str, DatasetFacet]] = Field(None, description="The facets for this dataset")


class InputDatasetFacet(BaseFacet):
    pass


class JobFacet(BaseFacet):
    pass


class OutputDatasetFacet(BaseFacet):
    pass


class RunFacet(BaseFacet):
    pass


class InputDataset(Dataset):
    inputFacets: Optional[Dict[str, InputDatasetFacet]] = Field(None, description="The input facets for this dataset.")


class Job(BaseModel):
    namespace: str = Field(..., description="The namespace containing that job", example="my-scheduler-namespace")
    name: str = Field(..., description="The unique name for that job within that namespace", example="myjob.mytask")
    facets: Optional[Dict[str, JobFacet]] = Field(None, description="The job facets.")


class OutputDataset(Dataset):
    outputFacets: Optional[Dict[str, OutputDatasetFacet]] = Field(
        None, description="The output facets for this dataset"
    )


class Run(BaseModel):
    runId: UUID = Field(..., description="The globally unique ID of the run associated with the job.")
    facets: Optional[Dict[str, RunFacet]] = Field(None, description="The run facets.")


class RunEvent(BaseModel):
    eventType: Optional[EventType] = Field(
        None,
        description="the current transition of the run state. It is required to issue 1 START event and 1 of [ COMPLETE, ABORT, FAIL ] event per run. Additional events with OTHER eventType can be added to the same run. For example to send additional metadata after the run is complete",
        example="START|RUNNING|COMPLETE|ABORT|FAIL|OTHER",
    )
    eventTime: datetime = Field(..., description="the time the event occurred at")
    run: Run
    job: Job
    inputs: Optional[List[InputDataset]] = Field(None, description="The set of **input** datasets.")
    outputs: Optional[List[OutputDataset]] = Field(None, description="The set of **output** datasets.")
    producer: AnyUrl = Field(
        ...,
        description="URI identifying the producer of this metadata. For example this could be a git url with a given tag or sha",
        example="https://github.com/OpenLineage/OpenLineage/blob/v1-0-0/client",
    )
    schemaURL: AnyUrl = Field(
        ...,
        description="The JSON Pointer (https://tools.ietf.org/html/rfc6901) URL to the corresponding version of the schema definition for this RunEvent",
        example="https://openlineage.io/spec/0-0-1/OpenLineage.json",
    )


class Model(BaseModel):
    __root__: RunEvent
