package config

import (
	"github.com/sirupsen/logrus"
	"starwiz.cn/sjy01/image-proc/pkg/payload"
)

type Config struct {
	CoRegistration CoRegistrationConfig `yaml:"coregistration" mapstructure:"coregistration"`
	Radiation      RadiationConfig      `yaml:"radiation" mapstructure:"radiation"`
	BrowserImg     BrowserImgConfig     `yaml:"browser_img" mapstructure:"browser_img"`
	Log            LogConfig            `yaml:"log" mapstructure:"log"`
	Dem            DemConfig            `yaml:"dem" mapstructure:"dem"`
	RPC            RPCConfig            `yaml:"rpc" mapstructure:"rpc"`
}

type LogConfig struct {
	LogLevel logrus.Level `yaml:"log_level" mapstructure:"log_level"`
	LogDir   string       `yaml:"log_dir" mapstructure:"log_dir"`
}

type CoRegistrationConfig struct {
	MssBands             int    `yaml:"mss_bands" mapstructure:"mss_bands"`
	PixelBytes           int    `yaml:"pixel_bytes" mapstructure:"pixel_bytes"`
	MssWidth             int    `yaml:"mss_width" mapstructure:"mss_width"`
	PanWidth             int    `yaml:"pan_width" mapstructure:"pan_width"`
	CRBlockNW            int    `yaml:"cr_block_nw" mapstructure:"cr_block_nw"`
	CRBlockNH            int    `yaml:"cr_block_nh" mapstructure:"cr_block_nh"`
	OverlappedBlockLines int    `yaml:"overlapped_block_lines" mapstructure:"overlapped_block_lines"`
	CRResampleMethod     string `yaml:"cr_resample_method" mapstructure:"cr_resample_method"`
	FUSBandOrder         string `yaml:"fus_band_order" mapstructure:"fus_band_order"`
}

type RadiationConfig struct {
	PANRemoveHfNoise    bool    `yaml:"pan_remove_hf_noise" mapstructure:"pan_remove_hf_noise"`
	MSSRemoveHfNoise    bool    `yaml:"mss_remove_hf_noise" mapstructure:"mss_remove_hf_noise"`
	SceneMomentMatching bool    `yaml:"scene_moment_matching" mapstructure:"scene_moment_matching"`
	HfRadiusRatio       float64 `yaml:"hf_radius_ratio" mapstructure:"hf_radius_ratio"`
	MinHistLevel        float64 `yaml:"min_hist_level" mapstructure:"min_hist_level"`
	MaxHistLevel        float64 `yaml:"max_hist_level" mapstructure:"max_hist_level"`
	HFBandStopWidth     int     `yaml:"hf_band_stop_width" mapstructure:"hf_band_stop_width"`
}

type DemConfig struct {
	DemType string `yaml:"dem_type" mapstructure:"dem_type"`
	DemDir  string `yaml:"dem_dir" mapstructure:"dem_dir"`
	Dem1Km  string `yaml:"dem_1km" mapstructure:"dem_1km"`
}

type BrowserImgConfig struct {
	Enhancement        map[string]string `yaml:"enhancement" mapstructure:"enhancement"`
	CumulativeCutLower float64           `yaml:"cumulative_cut_lower" mapstructure:"cumulative_cut_lower"`
	CumulativeCutUpper float64           `yaml:"cumulative_cut_upper" mapstructure:"cumulative_cut_upper"`
}

type RPCConfig struct {
	GridSize      int  `yaml:"grid_size" mapstructure:"grid_size"`
	AltitudeRange int  `yaml:"altitude_range" mapstructure:"altitude_range"`
	AltitudeLayer int  `yaml:"altitude_layer" mapstructure:"altitude_layer"`
	Method        int  `yaml:"method" mapstructure:"method"`
	Debug         bool `yaml:"debug" mapstructure:"debug"`
}

var GCONFIG Config

func init() {
	GCONFIG = Config{
		Log: LogConfig{
			LogLevel: logrus.DebugLevel,
			LogDir:   "log/SJY01ImageProc",
		},
		CoRegistration: CoRegistrationConfig{
			MssBands:             4,
			PixelBytes:           2,
			PanWidth:             payload.PAN_PIXEL_WIDTH,
			MssWidth:             payload.MSS_PIXEL_WIDTH,
			OverlappedBlockLines: 3000,
			CRBlockNW:            8,
			CRBlockNH:            4,
			CRResampleMethod:     "down_sample_pan",
			FUSBandOrder:         "RGB",
		},
		Radiation: RadiationConfig{
			PANRemoveHfNoise:    true,
			MSSRemoveHfNoise:    true,
			SceneMomentMatching: false,
			MinHistLevel:        0.3,
			MaxHistLevel:        0.6,
			HfRadiusRatio:       0.49,
			HFBandStopWidth:     24,
		},
		BrowserImg: BrowserImgConfig{
			Enhancement: map[string]string{
				"MSS": "StretchToCumulativeCutMinMax",
				"PAN": "StretchToMinimumMaximum",
				"FUS": "StretchToCumulativeCutMinMax",
			},
			CumulativeCutLower: 0.01,
			CumulativeCutUpper: 0.99,
		},
		Dem: DemConfig{
			DemType: "SRTM",
			DemDir:  "dem/SRTM",
			Dem1Km:  "dem/gdlebm.tif",
		},
		RPC: RPCConfig{
			GridSize:      3,
			AltitudeRange: 1000,
			AltitudeLayer: 5,
			Method:        2,
		},
	}
}
