package cn.reghao.autodop.dmaster.machine.service;

import cn.reghao.autodop.dmaster.machine.db.crud.MachineHostCrud;
import cn.reghao.autodop.dmaster.machine.db.query.MachineHostQuery;
import cn.reghao.autodop.dmaster.machine.model.po.MachineHost;
import cn.reghao.autodop.dmaster.machine.model.po.SshAuth;
import cn.reghao.autodop.dmaster.notification.model.po.NotifyGroup;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author reghao
 * @date 2019-11-15 08:48:04
 */
@Service
public class MachineService {
    private final MachineHostQuery hostQuery;
    private final MachineHostCrud hostCrud;

    public MachineService(MachineHostQuery hostQuery, MachineHostCrud hostCrud) {
        this.hostQuery = hostQuery;
        this.hostCrud = hostCrud;
    }

    public void setMachineNotify(String machineId, List<NotifyGroup> notifyGroups) {
        MachineHost machineHost = hostQuery.findByMachineId(machineId);
        machineHost.setNotifyGroups(notifyGroups);
        hostCrud.save(machineHost);
    }

    public void setSshAuth(String machineId, SshAuth sshAuth) {
        MachineHost machineHost = hostQuery.findByMachineId(machineId);
        machineHost.setSshAuth(sshAuth);
        hostCrud.save(machineHost);
    }

    public void setEnv(String machineId, String env) {
        MachineHost machineHost = hostQuery.findByMachineId(machineId);
        machineHost.setEnv(env);
        hostCrud.save(machineHost);
    }
}
