"""
Project:    PARTS Website
Author:     Edward Middleton-Smith
            Precision And Research Technology Systems Limited

Technology: View Models
Feature:    User View Model

Description:
Data model for user view
"""

# internal
from business_objects.tcg.user import User, Parameters_User
from datastores.datastore_user import DataStore_User
from forms.tcg.user import Filters_User
from helpers.helper_app import Helper_App
from models.model_view_base import Model_View_Base
# from routes import bp_home
# external
from typing import ClassVar

class Model_View_User(Model_View_Base):
    FLAG_ERROR_OAUTH: ClassVar[str] = 'error'
    FLAG_ERROR_DESCRIPTION_OAUTH: ClassVar[str] = 'error_description'
    FLAG_FIRSTNAME: ClassVar[str] = User.FLAG_FIRSTNAME
    FLAG_IS_EMAIL_VERIFIED: ClassVar[str] = User.FLAG_IS_EMAIL_VERIFIED
    FLAG_IS_SUPER_USER: ClassVar[str] = User.FLAG_IS_SUPER_USER
    FLAG_SURNAME: ClassVar[str] = User.FLAG_SURNAME
    FLAG_STATE_OAUTH: ClassVar[str] = 'state'
    form_filters: Filters_User = None
    form_filters_old: Filters_User
    users: list = None

    def __init__(self, form_filters_old, hash_page_current = Model_View_Base.HASH_PAGE_USER_ACCOUNT):
        super().__init__(hash_page_current = hash_page_current, form_filters_old = form_filters_old)
        self._title = 'Users'
        self.form_filters = form_filters_old

        # Helper_App.console_log(f'Form filters: {self.form_filters}')

        datastore = DataStore_User()

        parameters_user = Parameters_User.from_form_filters_user(self.form_filters)
        if self.hash_page_current == Model_View_Base.HASH_PAGE_USER_ACCOUNT:
            parameters_user.user_ids = str(self.user.user_id)
        # Helper_App.console_log(f'Query args: {parameters_user}')
        self.users, errors = datastore.get_many_user(parameters_user)
    