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

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.playlet.system.domain.PlayletPublicAccount;
import com.playlet.system.domain.PlayletPublicDetail;
import com.playlet.system.service.IPlayletPublicAccountService;
import com.playlet.system.service.IPlayletPublicDetailService;
import com.playlet.web.service.app.PlayletPublicDetailAppService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletPublicDetailAppServiceImpl implements PlayletPublicDetailAppService {

    private final IPlayletPublicDetailService iPlayletPublicDetailService;

    private final IPlayletPublicAccountService iPlayletPublicAccountService;

    @Override
    public PageInfo<PlayletPublicDetail> getList(PlayletPublicDetail playletPublicDetail, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PlayletPublicDetail> list =  iPlayletPublicDetailService.selectPlayletPublicDetailList(playletPublicDetail);
        list.forEach(model->{
            model.setPlayletPublicAccount(iPlayletPublicAccountService.selectPlayletPublicAccountById(model.getPublicId()));
        });
        return PageInfo.of(list);
    }

    @Override
    public PlayletPublicDetail getById(Long id) {
        PlayletPublicDetail model = iPlayletPublicDetailService.getById(id);
        model.setPlayletPublicAccount(iPlayletPublicAccountService.selectPlayletPublicAccountById(model.getPublicId()));
        return model;
    }

}
