package com.zhongshu.card.server.core.dao.org;

import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
import com.zhongshu.card.client.type.UserState;
import com.zhongshu.card.server.core.dao.org.extend.OrganizationUserDaoExtend;
import com.zhongshu.card.server.core.domain.org.Organization;
import com.zhongshu.card.server.core.domain.org.OrganizationUser;
import com.zhongshu.card.server.core.domain.org.UserAccount;

import java.util.List;

/**
 * @author TRX
 * @date 2024/3/21
 */
public interface OrganizationUserDao extends MongoDao<OrganizationUser>, OrganizationUserDaoExtend {

    List<OrganizationUser> findByIdIn(List<String> ids);

    OrganizationUser findTopById(String id);

    List<OrganizationUser> findByOrganizationAndIsAdmin(Organization organization, Boolean isAdmin);

    // 查询用户在机构的信息
    OrganizationUser findTopByOrganizationAndUser(Organization organization, UserAccount user);

    OrganizationUser findTopByUserIdAndOid(String userId, String oid);

    OrganizationUser findTopByUserAndProjectOidAndIsOrg(UserAccount user, String projectOid, Boolean isOrg);

    OrganizationUser findTopByOrganizationAndUserAndProjectOid(
            Organization organization, UserAccount user, String projectOid);

    OrganizationUser findTopByOrganizationAndUserAndState(Organization organization, UserAccount user, UserState state);

    OrganizationUser findTopByCodeAndOrganization(String code, Organization organization);

    OrganizationUser findTopByCodeAndProjectOid(String code, String projectOid);

    // 用户是否存在
    Boolean existsByOrganizationAndUser(Organization organization, UserAccount user);

    // 统计用户所在的机构数量
    long countByUserAndState(UserAccount user, UserState state);

    long countByUserAndStateAndAuthType(UserAccount user, UserState state, AuthType authType);

    long countByOrganization(Organization organization);

    void deleteByOrganization(Organization organization);

    // 查询用户所在机构
    List<OrganizationUser> findByUserAndAuthTypeAndState(UserAccount userAccount, AuthType authType, UserState state);

    List<OrganizationUser> findByUserAndAuthType(UserAccount userAccount, AuthType authType);

    List<OrganizationUser> findByUserIdAndProjectOidAndIsOrg(String userId, String projectOid, Boolean isOrg);

    List<OrganizationUser> findByUserId(String userId);

    List<OrganizationUser> findByUserIdAndProjectOid(String userId, String projectOid);

}
