import datetime as mytime

from faker import Faker
from playhouse.shortcuts import model_to_dict

from qa_data_manager.data_base_model import Services


class GenerateService:
    __fake = Faker('ru_RU')

    def __init__(self):
        self._doctor_id = ''
        self._is_active = 0
        self._type_of_service = 'av'
        self._price = 10
        self._duration = 5
        self._is_hidden = 0
        self._can_close = 0
        self._is_auto_resume = 0
        self._is_trial = 0
        self._is_default = 0
        self._name = 'tarif' + self.__fake.pystr()

    def with_doctor(self, doctor):
        self._doctor_id = doctor.get('id')
        return self

    def with_online_service_type(self):
        self._type_of_service = 'av'
        return self

    def with_chat_service_type(self):
        self._type_of_service = 'chat'
        return self

    def with_offline_service_type(self):
        self._type_of_service = 'offline'
        return self

    def with_online_type(self):
        self._type_of_service = 'av'
        return self

    def is_active(self):
        self._is_active = 1
        return self

    def is_can_close(self):
        self._can_close = 1
        return self

    def with_duration(self, duration):
        self._duration = duration
        return self

    def is_hidden(self):
        self._is_hidden = 1

    def with_price(self, price):
        self._price = price
        return self

    def is_trial(self):
        self._is_trial = 1
        return self

    def is_auto_resume(self):
        self._is_auto_resume = 1
        return self

    def is_default(self):
        self._is_default = 1
        return self

    def generate(self):
        service = Services(active=self._is_active,
                           can_close=self._can_close,
                           created_at=mytime.datetime.now(),
                           description='test tarif description',
                           doctor=self._doctor_id,
                           duration=self._duration,
                           is_auto_resume=self._is_auto_resume,
                           is_default=self._is_default,
                           is_hidden=self._is_hidden,
                           is_trial=self._is_trial,
                           name=self._name,
                           price=self._price,
                           service_type=self._type_of_service,
                           updated_at=mytime.datetime.now())
        service.save()
        return model_to_dict(service)
