package com.tykj.dev.config.task;

import com.tykj.dev.config.base.*;
import com.tykj.dev.config.repository.SystemConfigDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SystemConfigRun implements CommandLineRunner {

    @Autowired
    private SystemConfigDao systemConfigDao;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming main method arguments
     * @throws Exception on error
     */
    @Override
    public void run(String... args) throws Exception {
        if (systemConfigDao.findAll().size()==0){
            for (DeviceInvisibleRange d:DeviceInvisibleRange.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (DeviceLifeStatus d:DeviceLifeStatus.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (DeviceSecretLevel d:DeviceSecretLevel.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (MatchingRange d:MatchingRange.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (StorageType d:StorageType.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (AllotType d:AllotType.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (DeviceApplyType d:DeviceApplyType.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (DeviceNature d:DeviceNature.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (DeviceStyle d:DeviceStyle.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (Position d:Position.values()) {
                systemConfigDao.save(d.toDo());
            }
            for (MatchingType d:MatchingType.values()) {
                systemConfigDao.save(d.toDo());
            }
        }
    }
}
