package com.fs.xiaoshouyi.service.impl;

import com.fs.xiaoshouyi.mapper.XsyCompanyBindMapper;
import com.fs.xiaoshouyi.service.XsyCompanyBindService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class XsyCompanyBindServiceImpl implements XsyCompanyBindService {

    private final XsyCompanyBindMapper mapper;

    @Override
    public void bind(Long companyId, Long accountId) {
        if (companyId == null) {
            throw new RuntimeException("companyId不能为空");
        }
        if (accountId == null) {
            throw new RuntimeException("accountId不能为空");
        }
        if (!isCompanyBoundAccount(companyId, accountId)) {
            mapper.insertBind(companyId, accountId);
        }
    }

    @Override
    public void unbind(Long companyId, Long accountId) {
        mapper.deleteBind(companyId, accountId);
    }

    @Override
    public List<Long> getAccountIdsByCompanyId(Long companyId) {
        return mapper.selectAccountIdsByCompanyId(companyId);
    }

    @Override
    public boolean isCompanyBoundAccount(Long companyId, Long accountId) {
        return mapper.existsBind(companyId, accountId) > 0;
    }
}