package com.ruoyi.bst.team.service.impl;

import com.ruoyi.bst.store.domain.Store;
import com.ruoyi.bst.store.service.StoreConverter;
import com.ruoyi.bst.team.domain.Team;
import com.ruoyi.bst.team.domain.enums.TeamStatus;
import com.ruoyi.bst.team.domain.enums.TeamType;
import com.ruoyi.bst.team.service.TeamConverter;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

@Service
public class TeamConverterImpl implements TeamConverter {
    @Override
    public Team toPoByCreate(Team data) {
        if (data == null) {
            return null;
        }
        Team po = new Team();
        // 设置基本信息
        po.setStoreId(data.getStoreId());
        po.setBoothId(data.getBoothId());
        po.setName(data.getName());
        po.setPrefer(data.getPrefer());
        po.setType(data.getType());
        if (data.getType().equals(TeamType.BOOK.getCode())){
            ServiceUtil.assertion(data.getBookTime()==null,"预约拼桌时间不可以为空");
            po.setBookTime(data.getBookTime());
        }
        po.setTopic(data.getTopic());
        po.setLimitNum(data.getLimitNum());
        po.setLimitNum(data.getLimitNum());
        po.setCreateTime(DateUtils.getNowDate());
        po.setStatus(TeamStatus.NORMAL.getCode());
        return po;
    }

    @Override
    public Team toPoByUpdate(Team data) {
        if (data == null) {
            return null;
        }
        Team po = new Team();
        // 设置基本信息
        po.setId(data.getId());
        po.setStoreId(data.getStoreId());
        po.setBoothId(data.getBoothId());
        po.setName(data.getName());
        po.setPrefer(data.getPrefer());
        po.setType(data.getType());
        if (data.getType().equals(TeamType.BOOK.getCode())){
            ServiceUtil.assertion(data.getBookTime()==null,"预约拼桌时间不可以为空");
            po.setBookTime(data.getBookTime());
        }
        po.setTopic(data.getTopic());
        po.setLimitNum(data.getLimitNum());
        return po;
    }
}
