package meterControl

import (
	"log"
	"tgk-touch/internal/library/meterControl/Adl200Impl"
)
import "tgk-touch/internal/library/meterControl/Adl400Impl"

type MeterFirm string

const (
	ADL200 MeterFirm = "ADL200"
	ADL400 MeterFirm = "ADL400"
)

var (
	MeterFirms = map[string]MeterFirm{
		"ADL200": ADL200,
		"ADL400": ADL400,
	}
	meterControls      = make(map[MeterFirm]IMeterControl)
	readMeterControls  = make(map[MeterFirm]IReadMeter)
	writeMeterControls = make(map[MeterFirm]IWriteMeter)
)

func init() {
	// 注册 ADL200 单相电表控制器
	meterControls[ADL200] = Adl200Impl.GetAdl200Impl()
	readMeterControls[ADL200] = Adl200Impl.GetAdl200Impl()
	writeMeterControls[ADL200] = Adl200Impl.GetAdl200Impl()

	// 注册 ADL400 三相电表控制器
	meterControls[ADL400] = Adl400Impl.GetAdl400Impl()
	readMeterControls[ADL400] = Adl400Impl.GetAdl400Impl()
	writeMeterControls[ADL400] = Adl400Impl.GetAdl400Impl()
}

func GetMeterControls(firm MeterFirm) IMeterControl {
	log.Println("GetMeterControls", firm)
	_, ok := meterControls[firm]
	log.Println("GetMeterControls", ok)
	log.Println("GetMeterControls", meterControls)
	if v, ok := meterControls[firm]; ok {
		return v
	}
	return nil
}

func GetReadMeterControls(firm MeterFirm) IReadMeter {
	if v, ok := readMeterControls[firm]; ok {
		return v
	}
	return nil
}

func GetWriteMeterControls(firm MeterFirm) IWriteMeter {
	if v, ok := writeMeterControls[firm]; ok {
		return v
	}
	return nil
}
