package com.seer.teach.user.admin.convert;

import com.seer.teach.user.admin.request.AdminUpdateReq;
import com.seer.teach.user.admin.request.RegisterAdminReq;
import com.seer.teach.user.admin.response.AdminUserInfoResp;
import com.seer.teach.user.admin.response.AdminUserPageResp;
import com.seer.teach.user.admin.response.AuthorityRespData;
import com.seer.teach.user.entity.AuthorityEntity;
import com.seer.teach.user.entity.RoleEntity;
import com.seer.teach.user.entity.UserEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.Collection;
import java.util.List;

/**
 * @Author: Captain
 * @Description:
 * @Date: 2025-06-19 16:59
 */
@Mapper
public interface AdminUserConvert {

    AdminUserConvert INSTANCE = Mappers.getMapper(AdminUserConvert.class);

    UserEntity toEntity(RegisterAdminReq adminUserReq);


    AdminUserPageResp toPageResp(UserEntity userEntity);

    List<AdminUserPageResp> toPageRespList(List<UserEntity> userEntityList);

    @Mappings(
            {
                    @Mapping(target = "roles", source = "roles"),
                    @Mapping(target = "menus", source = "menus")
            }
    )
    AdminUserInfoResp toInfoResp(UserEntity userEntity, Collection<RoleEntity> roles, List<AuthorityRespData>  menus);


    @Mapping(target = "password", ignore = true)
    UserEntity convertOne(AdminUpdateReq  req);

    @Mapping(target = "password", ignore = true)
    UserEntity convertOne(RegisterAdminReq adminUserReq);
}