package cn.com.poc.ai_software_copyright.rest.impl;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

import cn.com.poc.ai_software_copyright.contant.AiSoftWareCopyRightEnum;
import cn.com.poc.ai_software_copyright.convert.BizSoftwareCopyrightConvert;
import cn.com.poc.ai_software_copyright.dto.SoftwareCopyRightDto;
import cn.com.poc.ai_software_copyright.entity.BizSoftwareCopyrightEntity;
import cn.com.poc.ai_software_copyright.query.SoftwareCopyrightQueryCondition;
import cn.com.poc.ai_software_copyright.query.SoftwareCopyrightQueryItem;
import cn.com.poc.ai_software_copyright.rest.BizSoftwareCopyrightRest;
import cn.com.poc.ai_software_copyright.service.BizSoftwareCopyrightService;
import cn.com.yict.framemax.data.model.PagingInfo;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

@Component
public class BizSoftwareCopyrightRestImpl implements BizSoftwareCopyrightRest {

    @Resource
    private BizSoftwareCopyrightService service;

    public SoftwareCopyRightDto getById(java.lang.Long id) throws Exception {
        Assert.notNull(id);
        return BizSoftwareCopyrightConvert.entityToDto(service.get(id));
    }

    public SoftwareCopyRightDto save(SoftwareCopyRightDto dto) throws Exception {
        Assert.notNull(dto);
        BizSoftwareCopyrightEntity entity = BizSoftwareCopyrightConvert.dtoToEntity(dto);
        entity.setGeneratedStatus(AiSoftWareCopyRightEnum.GENERATED_STATUS.Daft.name());
        return BizSoftwareCopyrightConvert.entityToDto(service.save(entity));
    }

    public void deletedById(java.lang.Long id) throws Exception {
        Assert.notNull(id);
        service.deletedById(id);
    }

    @Override
    public List<SoftwareCopyRightDto> querySoftwareCopyRight(String query, String generatedStatus,
                                                             PagingInfo pagingInfo) {

        SoftwareCopyrightQueryCondition condition = new SoftwareCopyrightQueryCondition();
        condition.setGeneratedStatus(generatedStatus);
        condition.setQuery(query);
        List<SoftwareCopyrightQueryItem> softwareCopyrightQueryItems =
                service.softwareCopyrightQuery(condition, pagingInfo);
        return softwareCopyrightQueryItems.stream().map(BizSoftwareCopyrightConvert::softwareCopyrightQueryItemToDto)
                .collect(
                        Collectors.toList());
    }
}