# Generated by sila2.code_generator; sila2.__version__: 0.12.2
from __future__ import annotations

import string
from typing import TYPE_CHECKING

from opentrons.protocol_api import ProtocolContext, Labware
from sila2.server import MetadataDict

from ..generated.sessionmanagement import (
    SessionCreate_Responses,
    SessionDelete_Responses,
    SessionManagementBase,
)

if TYPE_CHECKING:
    from ..server import Server

import opentrons.execute
import uuid

from ..base import Base


class SessionManagementImpl(SessionManagementBase):
    def __init__(self, parent_server: Server, base: Base) -> None:
        super().__init__(parent_server=parent_server)
        self.base = base

    def SessionCreate(self, *,
                      metadata: MetadataDict) -> SessionCreate_Responses:
        new_id = self.base.start_session()
        if new_id is str:
            protocol = opentrons.execute.get_protocol_api("2.19")
            self.base.set_session_protocol(protocol)
            return SessionCreate_Responses(SessionToken=new_id)
        raise "Machine is already in use"

    def SessionDelete(self, SessionToken: str, *,
                      metadata: MetadataDict) -> SessionDelete_Responses:
        self.base.end_session(SessionToken)
        return SessionDelete_Responses()
