import random


class ChatGPTWrap:
    def __init__(self, use_chatgpt_placeholder = False):
        self.use_chatgpt_placeholder = use_chatgpt_placeholder

        # true chatgpt
        if not use_chatgpt_placeholder:

            print("Initializing ChatGPT... ", end="")

            with open("system_instructions.txt", "r", encoding="utf-8") as f:
                self.system_inst_template = f.read()


            #### true openai chat gpt initialization stuff below (everything that needs to be done only once) ####
            raise NotImplementedError("True ChatGPT is not implemented yet!")




            print("Done!")

        # placeholder chatgpt
        else:
            print("Using ChatGPT placeholder!")
            self.message_idx = 0



    def init_order(self, phone_number, order_items, delivery_address, payment_method):
        self.phone_number = phone_number
        self.order_items = order_items
        self.delivery_address = delivery_address
        self.payment_method = payment_method

        # true chatgpt
        if not self.use_chatgpt_placeholder:
            # generate system instructions from template
            self.system_inst = self.system_inst_template.format(
                phone_number = self.phone_number,
                order_items = self.order_items,
                delivery_address = self.delivery_address,
                payment_method = self.payment_method
            )

            #### true openai chat gpt system instructions initialization stuff below ####
            ##### (everything that needs to be done each assistant session like some chat gpt conversation cleanup) ####


    def get_response(self, input_message):
        # true chatgpt
        if not self.use_chatgpt_placeholder:
            #### true openai chat gpt response stuff below ####



            pass # return response

        # placeholder chatgpt
        else:
            choices = (
                self.phone_number,
                self.order_items,
                self.delivery_address,
                self.payment_method
            )

            self.message_idx += 1

            return f"czat dżi pi ti plejsholder {random.choice(choices)}{' CALLEND' if self.message_idx == 3 else ''}"