# Copyright 2024 Soul Machines Ltd

# 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.

# generated by datamodel-codegen:
#   filename:  api.yml
#   timestamp: 2024-04-02T22:17:10+00:00

from __future__ import annotations

from enum import Enum
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Extra, Field

from . import common


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

    public: Optional[Dict[str, Any]] = None


class Output(BaseModel):
    text: Optional[str] = Field(
        default=None,
        description="Text for the digital person to speak",
        example="Here is a cat",
    )
    variables: Optional[Variables] = None


class HistoryInput(BaseModel):
    text: Optional[str] = Field(default=None, description="Input text")


class ProcessingStage(Enum):
    pre = "pre"
    post = "post"


class HistoryOutputMetadata(BaseModel):
    endConversation: Optional[bool] = Field(
        default=None,
        description=(
            "Used to indicate whether the current interaction with the skill should be"
            " concluded.  Set to false if you want the skill to handle further"
            " conversation turns with the user.\n"
        ),
    )
    memory: Optional[List[common.Memory]] = Field(
        default=None,
        description=(
            "Information stored from the most recent response received from the"
            " endpoint"
        ),
        example=[
            {
                "name": "memory1",
                "scope": "PRIVATE",
                "value": "value1",
                "session_id": "456ABC456",
            },
            {"name": "memory2", "scope": "PUBLIC", "value": {"name": "string"}},
            {
                "name": "memory3",
                "scope": "PUBLIC",
                "value": 1,
                "session_id": "123ABC123",
            },
        ],
    )
    projectId: Optional[str] = Field(
        default=None,
        description="ID of the Project created in DDNA Studio",
        example="ABC123",
    )
    sessionId: Optional[str] = Field(
        default=None,
        description="A UUIDv4 identifier for this particular session",
        example="7600aff2-6ebd-44de-bcd2-1facd8ab4f29",
    )


class HistoryOutput(BaseModel):
    text: Optional[str] = Field(default=None, description="Input text")
    variables: Optional[Variables] = None
    metadata: Optional[HistoryOutputMetadata] = None


class HistoryItem(BaseModel):
    input: Optional[HistoryInput] = None
    output: Optional[HistoryOutput] = None


class ConversationHistory(BaseModel):
    __root__: List[HistoryItem]


class InitRequest(BaseModel):
    projectId: str = Field(
        ...,
        description=(
            "Unique identifier for the project using the skill and its deployment"
            " environment. For example, each project will give a unique ID for either"
            " of its preview and public deployments."
        ),
        example="ABC123",
    )
    deploymentEnvironment: common.DeploymentEnvironment
    ownerId: Optional[str] = None
    organizationId: Optional[str] = None
    config: Dict[str, Any] = Field(
        ...,
        description="Skill configuration data will be included in this object.\n",
        example={"config1": "string", "config2": 20, "config3": {"name": "value"}},
    )


class ExecuteRequest(BaseModel):
    projectId: str = Field(
        ...,
        description=(
            "Unique identifier for the project using the skill and its deployment"
            " environment. For example, each project will give a unique ID for either"
            " of its preview and public deployments."
        ),
        example="ABC123",
    )
    deploymentEnvironment: common.DeploymentEnvironment
    sessionId: str = Field(
        ...,
        description="A UUIDv4 identifier for this particular session",
        example="7600aff2-6ebd-44de-bcd2-1facd8ab4f29",
    )
    intent: Optional[common.Intent] = None
    text: str = Field(..., description="User input", example="Show me a cat")
    memory: List[common.Memory] = Field(
        ...,
        description=(
            "Information stored from the most recent response received from the"
            " endpoint"
        ),
        example=[
            {
                "name": "memory1",
                "scope": "PRIVATE",
                "value": "value1",
                "session_id": "456ABC456",
            },
            {"name": "memory2", "scope": "PUBLIC", "value": {"name": "string"}},
            {
                "name": "memory3",
                "scope": "PUBLIC",
                "value": 1,
                "session_id": "123ABC123",
            },
        ],
    )
    config: Optional[Dict[str, Any]] = Field(
        default=None,
        description=(
            "Skill configuration data will be included in this object. This property"
            " will only be  included if the Skill is Stateless (i.e. no endpointSession"
            " is provided).\n"
        ),
        example={"config1": "string", "config2": 20, "config3": {"name": "value"}},
    )
    context: Optional[Dict[str, Any]] = Field(
        default=None,
        description=(
            "Contains the context of the request, is also used to send DP specific data"
            " e.g. EQ data. Might contain Processing_Stage stating if a request is for"
            " a pre or post stage. Might contain Conversation_History of up to 5"
            " conversation turns.\n"
        ),
        example={
            "Current_Time": "11 05 pm",
            "FacePresent": 1,
            "Turn_Id": "2050c232-f49c-4cfe-a440-13bde4af120f",
            "stt_final_result_string": "Show me a cat",
            "UserTurn_IsAttentive": 0.3602287173271179,
            "UserTurn_IsTalking": None,
            "UserTurn_TextAnger": 0,
            "UserTurn_TextCare": 0,
            "UserTurn_TextConcern": 0,
            "UserTurn_TextDisgust": 0,
            "UserTurn_TextDistress": 0,
            "UserTurn_TextExcitement": 0,
            "UserTurn_TextFear": 0,
            "UserTurn_TextInterest": 0,
            "UserTurn_TextJoy": 0,
            "UserTurn_TextShame": 0,
            "UserTurn_TextSurprise": 0,
            "UserTurn_TextValence": 0,
            "User_Turn_Confusion": None,
            "User_Turn_Negativity": None,
            "User_Turn_Positivity": 0.5356926918029785,
            "is_speaking": False,
            "PersonaTurn_IsAttentive": None,
            "PersonaTurn_IsTalking": None,
            "Persona_Turn_Confusion": None,
            "Persona_Turn_Negativity": None,
            "Persona_Turn_Positivity": None,
        },
    )


class ExecuteResponse(BaseModel):
    output: Optional[Output] = None
    intent: Optional[common.Intent] = None
    memory: Optional[List[common.Memory]] = Field(
        default=None,
        example=[
            {
                "name": "memory1",
                "scope": "PRIVATE",
                "value": "value1",
                "session_id": "456ABC456",
            },
            {"name": "memory2", "scope": "PUBLIC", "value": {"name": "string"}},
            {
                "name": "memory3",
                "scope": "PUBLIC",
                "value": 1,
                "session_id": "123ABC123",
            },
        ],
    )
    endConversation: bool = Field(
        ...,
        description=(
            "Used to indicate whether the current interaction with the skill should be"
            " concluded.  Set to false if you want the skill to handle further"
            " conversation turns with the user.\n"
        ),
    )
    endRouting: Optional[bool] = Field(
        default=None,
        description=(
            "Used to indicate that no further routing should take place. Note that pre"
            " and post processing skills will not be skipped.\n"
        ),
        example=False,
    )


class SessionRequest(BaseModel):
    projectId: str = Field(
        ...,
        description=(
            "Unique identifier for the project using the skill and its deployment"
            " environment. For example, each project will give a unique ID for either"
            " of its preview and public deployments."
        ),
        example="ABC123",
    )
    deploymentEnvironment: common.DeploymentEnvironment
    sessionId: str = Field(
        ...,
        description="A UUIDv4 identifier for this particular session",
        example="7600aff2-6ebd-44de-bcd2-1facd8ab4f29",
    )
    config: Optional[Dict[str, Any]] = Field(
        default=None,
        description="Includes Skill configuration data in this object.",
        example={"config1": "string", "config2": 20, "config3": {"name": "value"}},
    )
    memory: Optional[List[common.Memory]] = Field(
        default=None,
        description=(
            "Information stored from the most recent response received from the"
            " endpoint"
        ),
        example=[
            {
                "name": "memory1",
                "scope": "PRIVATE",
                "value": "value1",
                "session_id": "456ABC456",
            },
            {"name": "memory2", "scope": "PUBLIC", "value": {"name": "string"}},
            {
                "name": "memory3",
                "scope": "PUBLIC",
                "value": 1,
                "session_id": "123ABC123",
            },
        ],
    )


class SessionResponse(BaseModel):
    memory: Optional[List[common.Memory]] = Field(
        default=None,
        example=[
            {
                "name": "memory1",
                "scope": "PRIVATE",
                "value": "value1",
                "session_id": "456ABC456",
            },
            {"name": "memory2", "scope": "PUBLIC", "value": {"name": "string"}},
            {
                "name": "memory3",
                "scope": "PUBLIC",
                "value": 1,
                "session_id": "123ABC123",
            },
        ],
    )


class DeleteRequest(BaseModel):
    deploymentEnvironment: common.DeploymentEnvironment
