# Copyright 2022 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.db import models, IntegrityError
from django.db.models import Q
from django.conf import settings
from sis_provisioner.dao.account import (
    valid_academic_account_sis_id, adhoc_account_sis_id)
from sis_provisioner.dao.canvas import (
    get_account_by_id, get_all_sub_accounts, update_account_sis_id)
from sis_provisioner.models import ImportResource
from sis_provisioner.exceptions import AccountPolicyException
from logging import getLogger

logger = getLogger(__name__)


class AccountManager(models.Manager):
    def find_by_type(self, account_type=None, is_deleted=False):
        kwargs = {}
        if account_type:
            kwargs['account_type'] = account_type
        if is_deleted:
            kwargs['is_deleted'] = True

        return super(AccountManager, self).get_queryset().filter(**kwargs)

    def find_by_soc(self, account_type=''):