package com.playlet.web.service.app.impl;

import com.playlet.system.domain.PlayletPublicUser;
import com.playlet.system.service.IPlayletPublicUserService;
import com.playlet.web.service.app.PlayletPublicUserAppService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletPublicUserAppServiceImpl implements PlayletPublicUserAppService {

    private final IPlayletPublicUserService iPlayletPublicUserService;

    @Override
    public PlayletPublicUser addPublicUser(PlayletPublicUser publicUser) {
        iPlayletPublicUserService.insertPlayletPublicUser(publicUser);
        return publicUser;
    }

    @Override
    public PlayletPublicUser findByUnionIdAndPublicId(PlayletPublicUser publicUser) {
        List<PlayletPublicUser> list =iPlayletPublicUserService.lambdaQuery()
                .eq(PlayletPublicUser::getPublicId, publicUser.getPublicId())
                .eq(PlayletPublicUser::getUnionId, publicUser.getUnionId())
                .list();
        if(CollectionUtils.isNotEmpty(list)){
            return list.get(0);
        }
        return null;
    }

}
