# Copyright 2022 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:  skill-api.yml
#   timestamp: 2022-03-30T02:12:35+00:00

from __future__ import annotations

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

from pydantic import BaseModel, Extra, Field


class Intent(BaseModel):
    name: Optional[str] = Field(
        None,
        description="""Name of intent that handled the request or 'NO_MATCH' if a
                       fallback is hit""",
    )
    confidence: Optional[float] = Field(
        None, description="Confidence of the intent matched in the range 0-1"
    )


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

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


class Output(BaseModel):
    text: Optional[str] = None
    variables: Optional[Variables] = None


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


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


class MemoryScope(Enum):
    PRIVATE = "PRIVATE"
    PUBLIC = "PUBLIC"


class Memory(BaseModel):
    name: str = Field(..., description="Identifier for the memory value")
    value: Any = Field(..., description="Memory value (can be of any type)")
    session_id: Optional[str] = Field(
        None, description="Optional session ID to identify this memory value"
    )
    scope: Optional[MemoryScope] = None


class ExecuteResponse(BaseModel):
    output: Optional[Output] = None
    intent: Optional[Intent] = None
    memory: Optional[List[Memory]] = None
    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""",
    )


class SessionRequest(BaseModel):
    projectId: str = Field(
        ..., description="(Future functionality) Salted hash of DDNA Studio Project ID"
    )
    sessionId: str
    config: Optional[Dict[str, Any]] = None
    memory: Optional[List[Memory]] = None


class SessionResponse(BaseModel):
    memory: Optional[List[Memory]] = None


class HistoryOutputMetadata(BaseModel):
    endConversation: Optional[bool] = Field(
        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[Memory]] = Field(
        None,
        description="""Information stored from the most recent response received from
        the endpoint""",
    )
    projectId: Optional[str] = Field(
        None, description="(Future functionality) Salted hash of DDNA Studio Project ID"
    )
    sessionId: Optional[str] = Field(
        None, description="A unique identifier for this particular session"
    )


class HistoryOutput(BaseModel):
    text: Optional[str] = Field(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 Context(BaseModel):
    class Config:
        extra = Extra.allow

    Processing_Stage: Optional[ProcessingStage] = None
    Conversation_History: Optional[ConversationHistory] = None


class ExecuteRequest(BaseModel):
    projectId: str = Field(
        ..., description="(Future functionality) Salted hash of DDNA Studio Project ID"
    )
    sessionId: str = Field(
        ..., description="A unique identifier for this particular session"
    )
    intent: Optional[Intent] = None
    text: str = Field(..., description="User input")
    memory: List[Memory] = Field(
        ...,
        description="""Information stored from the most recent response received from
        the endpoint""",
    )
    context: Optional[Context] = Field(
        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 contains history to up to 5 conversation
                       turns.\n""",
    )
    config: Optional[Dict[str, Any]] = Field(
        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
        sessionEndpoint is provided).\n""",
    )
