import requests
class API(object):
    def __init__(self):
        
        self.headers = {
            'APPTOKEN': "infopetaniapptoken",
            'Content-Type': "application/json",
            'cache-control': "no-cache",
            'Postman-Token': "4b0ec07f-7f67-4636-a0ef-eb07e77ad73b"
            }
    
    def post_message(self,author_id,role,room_id,content,type_mes):
        url = "http://128.199.125.236/infopetani/gateway-v3/public/chat2"
        payload = "{\"author_id\": \""+author_id+"\",\"role\": \""+role+"\",\"room_id\": \""+room_id+"\",\"content\": \""+content+"\",\"type\": \""+type_mes+"\"}"
        headers = self.headers
        response = requests.request("POST", url, data=payload, headers=headers)
        return response.text

    def update_read_message(self,room_id,target_id):
        url = "http://128.199.125.236/infopetani/gateway-v3/public/chat-update-read2"
        payload = "{\"target_id\": \""+target_id+"\",\"room_id\": \""+room_id+"\"}"
        headers = self.headers
        response = requests.request("POST", url, data=payload, headers=headers)
        return response.text

    def update_read_message_in_room(self,room_id,author_id):
        url = "http://128.199.125.236/infopetani/gateway-v3/public/chat-update-read-in-room2"
        payload = "{\"author_id\": \""+author_id+"\",\"room_id\": \""+room_id+"\"}"
        headers = self.headers
        response = requests.request("POST", url, data=payload, headers=headers)
        return response.text

    def send_notif(self,member_id,room_id,author_name,message,type_mes,date,time,category):
        # member_id,room_id,author_name,message,type_message,date,time,category
        url = "http://128.199.125.236/infopetani/gateway-v3/public/push-notif"
        payload = "{\"member_id\": \""+member_id+"\",\"room_id\": \""+room_id+"\",\"author_name\": \""+author_name+"\",\"message\": \""+message+"\",\"type\": \""+type_mes+"\",\"date\": \""+date+"\",\"time\": \""+time+"\",\"category\": \""+category+"\"}"
        headers = self.headers
        response = requests.request("POST", url, data=payload, headers=headers)
        return response.text
