import json
import os
from datetime import datetime, timedelta


class MockResponse:
    def __init__(self, status_code, data={}):
        self.status_code = status_code
        self.data = data

    def json(self):
        return self.data


## Setup json data

def make_orders_valid(orders):
    for order in orders:
        if 'created_at' in order:
            yesterday = datetime.now() - timedelta(1)
            order['created_at'] = datetime.strftime(yesterday, '%Y-%m-%d %H:%M:%S')

    return orders

# Load data
dir_path = os.path.dirname(os.path.realpath(__file__))

with open('{}/mock_data/valid_teacher_orders.json'.format(dir_path), 'r') as file:
    valid_teacher_order_data = file.read()

with open('{}/mock_data/valid_student_orders.json'.format(dir_path), 'r') as file:
    valid_student_order_data = file.read()

with open('{}/mock_data/me_data.json'.format(dir_path), 'r') as file:
    me_data = file.read()

with open('{}/mock_data/email_not_confirmed_me.json'.format(dir_path), 'r') as file:
    not_confirmed_email_me_data = file.read()

ME_DATA = json.loads(me_data)
NOT_CONFIRMED_ME = json.loads(not_confirmed_email_me_data)

valid_teacher_orders = json.loads(valid_teacher_order_data)
VALID_TEACHERS_ORDERS = make_orders_valid(valid_teacher_orders)

valid_student_orders = json.loads(valid_student_order_data)
VALID_STUDENT_ORDERS = make_orders_valid(valid_student_orders)
