package com.zcloud.personnel.positioning.service;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.personnel.positioning.api.FenceServiceI;
import com.zcloud.personnel.positioning.command.FenceAddExe;
import com.zcloud.personnel.positioning.command.FenceCompanyAreaSaveExe;
import com.zcloud.personnel.positioning.command.FenceFindsPullService;
import com.zcloud.personnel.positioning.command.FenceRemoveExe;
import com.zcloud.personnel.positioning.command.FenceUpdateExe;
import com.zcloud.personnel.positioning.command.query.FenceQueryExe;
import com.zcloud.personnel.positioning.dto.FenceAddCmd;
import com.zcloud.personnel.positioning.dto.FenceCompanyAreaSaveCmd;
import com.zcloud.personnel.positioning.dto.FenceCompanyPageQry;
import com.zcloud.personnel.positioning.dto.FencePageQry;
import com.zcloud.personnel.positioning.dto.FenceSyncCmd;
import com.zcloud.personnel.positioning.dto.FenceUpdateCmd;
import com.zcloud.personnel.positioning.dto.clientobject.FenceCO;
import com.zcloud.personnel.positioning.dto.clientobject.FenceCompanyAreaCO;
import com.zcloud.personnel.positioning.dto.clientobject.FenceCompanyStatCO;
import com.zcloud.personnel.positioning.dto.clientobject.FenceSyncCO;
import com.zcloud.personnel.positioning.dto.clientobject.OptionCO;
import com.zcloud.personnel.positioning.persistence.dataobject.FenceDO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class FenceServiceImpl implements FenceServiceI {
    private final FenceAddExe fenceAddExe;
    private final FenceUpdateExe fenceUpdateExe;
    private final FenceRemoveExe fenceRemoveExe;
    private final FenceQueryExe fenceQueryExe;
    private final FenceCompanyAreaSaveExe fenceCompanyAreaSaveExe;
    private final FenceFindsPullService fenceFindsPullService;

    @Override
    public PageResponse<FenceCompanyStatCO> listCompanyStats(FenceCompanyPageQry qry) {
        return fenceQueryExe.listCompanyStats(qry);
    }

    @Override
    public List<OptionCO> listCompanyOptions(String keyword) {
        return fenceQueryExe.listCompanyOptions(keyword);
    }

    @Override
    public PageResponse<FenceCO> listPage(FencePageQry qry) {
        return fenceQueryExe.execute(qry);
    }

    @Override
    public List<FenceCO> listAll() {
        return fenceQueryExe.listAll();
    }

    @Override
    public FenceCO queryById(Long id) {
        return fenceQueryExe.queryById(id);
    }

    @Override
    public FenceCompanyAreaCO queryCompanyArea(String corpinfoId, String corpinfoName) {
        return fenceCompanyAreaSaveExe.query(corpinfoId, corpinfoName);
    }

    @Override
    public SingleResponse<FenceCO> add(FenceAddCmd cmd) {
        FenceDO fenceDO = fenceAddExe.execute(cmd);
        return SingleResponse.of(fenceQueryExe.queryById(fenceDO.getId()));
    }

    @Override
    public FenceCompanyAreaCO saveCompanyArea(FenceCompanyAreaSaveCmd cmd) {
        return fenceCompanyAreaSaveExe.save(cmd);
    }

    @Override
    public FenceSyncCO syncFromFinds(FenceSyncCmd cmd) {
        return fenceFindsPullService.sync(cmd);
    }

    @Override
    public void edit(FenceUpdateCmd cmd) {
        fenceUpdateExe.execute(cmd);
    }

    @Override
    public void enable(Long id) {
        fenceUpdateExe.changeStatus(id, true);
    }

    @Override
    public void disable(Long id) {
        fenceUpdateExe.changeStatus(id, false);
    }

    @Override
    public void remove(Long id) {
        fenceRemoveExe.execute(id);
    }

    @Override
    public void removeBatch(Long[] ids) {
        fenceRemoveExe.execute(ids);
    }
}
