# WARNING: This file is autogenerated by FHIR Schema Codegen.
# https://github.com/fhir-schema/fhir-schema-codegen
# Any manual changes made to this file may be overwritten.

from __future__ import annotations
from pydantic import ConfigDict, Field
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Address,
    BackboneElement,
    CodeableConcept,
    Coding,
    ContactPoint,
    Identifier,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


class LocationHoursOfOperation(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    all_day: bool | None = Field(None, alias="allDay", serialization_alias="allDay")
    closing_time: str | None = Field(
        None, alias="closingTime", serialization_alias="closingTime"
    )
    days_of_week: (
        PyList[Literal["mon", "tue", "wed", "thu", "fri", "sat", "sun"]] | None
    ) = Field(None, alias="daysOfWeek", serialization_alias="daysOfWeek")
    opening_time: str | None = Field(
        None, alias="openingTime", serialization_alias="openingTime"
    )


class LocationPosition(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    altitude: float | None = Field(
        None, alias="altitude", serialization_alias="altitude"
    )
    latitude: float = Field(alias="latitude", serialization_alias="latitude")
    longitude: float = Field(alias="longitude", serialization_alias="longitude")


class Location(DomainResource):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    resource_type: str = Field(
        default="Location",
        alias="resourceType",
        serialization_alias="resourceType",
        frozen=True,
        pattern="Location",
    )

    address: Address | None = Field(
        None, alias="address", serialization_alias="address"
    )
    alias: PyList[str] | None = Field(None, alias="alias", serialization_alias="alias")
    availability_exceptions: str | None = Field(
        None,
        alias="availabilityExceptions",
        serialization_alias="availabilityExceptions",
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    endpoint: PyList[Reference] | None = Field(
        None, alias="endpoint", serialization_alias="endpoint"
    )
    hours_of_operation: PyList[LocationHoursOfOperation] | None = Field(
        None, alias="hoursOfOperation", serialization_alias="hoursOfOperation"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    managing_organization: Reference | None = Field(
        None, alias="managingOrganization", serialization_alias="managingOrganization"
    )
    mode: Literal["instance", "kind"] | None = Field(
        None, alias="mode", serialization_alias="mode"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    operational_status: Coding | None = Field(
        None, alias="operationalStatus", serialization_alias="operationalStatus"
    )
    part_of: Reference | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    physical_type: CodeableConcept | None = Field(
        None, alias="physicalType", serialization_alias="physicalType"
    )
    position: LocationPosition | None = Field(
        None, alias="position", serialization_alias="position"
    )
    status: Literal["active", "suspended", "inactive"] | None = Field(
        None, alias="status", serialization_alias="status"
    )
    telecom: PyList[ContactPoint] | None = Field(
        None, alias="telecom", serialization_alias="telecom"
    )
    type: PyList[CodeableConcept] | None = Field(
        None, alias="type", serialization_alias="type"
    )

    def to_json(self, indent: int | None = None) -> str:
        return self.model_dump_json(
            exclude_unset=True, exclude_none=True, indent=indent
        )

    @classmethod
    def from_json(cls, json: str) -> Location:
        return cls.model_validate_json(json)
