import json


def contact(request):
    """
    Create Json response about the contact to the company.
    :param request: POST request from "Contact" dialogflow intent
    :return: Json response that contains spoken and display prompt and also basic card about contact to company
    """
    speech_text_pl = "Dane adresowe Best Transport Polska S.A. W Czym mogę Ci jeszcze pomóc?"
    display_text_pl = "Dane adresowe Best Transport Polska S.A. W Czym mogę Ci jeszcze pomóc?"
    basic_card_pl = {
        "basicCard": {
            "title": "Kontakt",
            "formattedText": "___ul.___ Piotrkowska 1 90-000 Łódź  \n___tel.___ 111222333  \n___e-mail___ kontakt.besttransport@com.pl  \n"
                             "___Otwarte:___  \npon.- pt. 7.00 - 19.00  \nsob. 7.00 - 16.00",
            "image": {
                "url": "https://polskazachwyca.pl/wp-content/uploads/2017/10/%C5%82%C3%B3d%C5%BA-piotrkowska-shutterstock_441654322.jpg",
                "accessibilityText": "Kontakt"
              },
            "imageDisplayOptions": "CROPPED"
            }
          }
    suggestions_pl = [{"title": "Oferty"}, {"title": "Zlecenia"}, {"title": "Zapytania"}, {"title": "Konto"},
                      {"title": "Inne"}]

    speech_text_en = "Address details of Best Transport Poland S.A. How can I help you?"
    display_text_en = "Address details of Best Transport Poland S.A. How can I help you?"
    basic_card_en = {
        "basicCard": {
            "title": "Contact",
            "formattedText": "__st.__ Piotrkowska 1 90-000 Lodz  \n__tel.no.__ +48 111222333  \n__e-mail__ kontakt.besttransport@com.pl  \n"
                             "__Open:__  \nmon.- fri. 7.00 - 19.00  \nsat. 7.00 - 16.00",
            "image": {
                "url": "https://polskazachwyca.pl/wp-content/uploads/2017/10/%C5%82%C3%B3d%C5%BA-piotrkowska-shutterstock_441654322.jpg",
                "accessibilityText": "Contact"
            },
            "imageDisplayOptions": "CROPPED"
        }
    }
    suggestions_en = [{"title": "Offers"}, {"title": "Orders"}, {"title": "Inquiries"}, {"title": "Account"},
                      {"title": "Others"}]

    with open('api/response.json') as json_file:
        contact = json.load(json_file)

    part_to_modify = contact['payload']['google']['richResponse']

    if request.data['queryResult']['languageCode'] == 'pl':
        part_to_modify['items'][0]['simpleResponse']['textToSpeech'] = speech_text_pl
        part_to_modify['items'][0]['simpleResponse']['displayText'] = display_text_pl
        part_to_modify['items'].append(basic_card_pl)
        part_to_modify['suggestions'] = suggestions_pl
    else:
        part_to_modify['items'][0]['simpleResponse']['textToSpeech'] = speech_text_en
        part_to_modify['items'][0]['simpleResponse']['displayText'] = display_text_en
        part_to_modify['items'].append(basic_card_en)
        part_to_modify['suggestions'] = suggestions_en

    contact['payload']['google']['richResponse'] = part_to_modify
    return contact