# Copyright 2023 DeepMind Technologies Limited
#
# 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.

"""A base environment for scheduling with private info.
"""

import dataclasses

from open_spiel.python.games.chat_games.envs.comm_substrates import schedules
from open_spiel.python.games.chat_games.envs.utils import header


action_keys = tuple(['tone'])
info_keys = tuple(['day_prefs', 'ooo_days'])

w_opts = (schedules.W_OPTS_PREFIX +
          'Out of Office Days:\n{ooo_days}\n\n' +
          'Day Preferences:\n{day_prefs}\n\n' +
          'Tone: Use a {tone} tone.\n' +
          schedules.PLAIN)

ab = schedules.PLAIN.format(sender='Alice', receiver='Bob') + '\n\n'
ba = schedules.PLAIN.format(sender='Bob', receiver='Alice') + '\n\n'
cd = schedules.PLAIN.format(sender='Charlie', receiver='David') + '\n\n'
dc = schedules.PLAIN.format(sender='David', receiver='Charlie') + '\n\n'

context = '''An intelligent assistant is looking at dialogs between two people
trying to decide when to meet, and determines whether they have managed to agree
on a meeting time, and if so when the meeting is set to occur.

Example 1:
{s1}Hi Bob, can we meet on Monday?
{s2}No, I am out of the office on Monday. How about Tuesday?
{s3}Well, I am in the office on Tuesday but I would rather keep my schedule
free. Can we do Friday instead.
{s4}Great, Friday it is. See you then!

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<END OF EXAMPLE 1>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Summary: Alice suggests Monday, Bob declines. Bob suggests Tuesday. Alice
declines. Alice suggests Friday. Bob agrees.
Outcome Summary: Meeting agreed on Friday.

Example 2:
{s5}Hi David, would you like to meet on Friday?
{s6}I hate working on Fridays. Can't we meet on Tuesday?
{s7}On Tuesday I am out of the office, and Wednesday also doesn't work for me.
How do you feel about meeting on Saturday?
{s8}Excellent, let's meet on Saturday.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<END OF EXAMPLE 2>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Summary: Charlie suggests Friday. David declines. David suggests Tuesday.
Charlie declines. Charlie suggests Saturday. David agrees.
Outcome Summary: Meeting agreed on Saturday.

Example 3:
'''.format(s1=ab, s2=ba, s3=ab, s4=ba, s5=cd, s6=dc, s7=cd, s8=dc)

HEADER = header.Header(schedules.PLAIN,
                       w_opts,
                       schedules.strip_msg,
                       schedules.SPECIAL_CHARS,
                       action_keys,
                       info_keys,
                       context)


@dataclasses.dataclass(frozen=True)
class Scenario(header.BaseScenario):
  ooo_days: str
  day_prefs: str
  tone: str = 'calm'
