package config

import (
	"SafelineAPI/internal/app/logger"
	"SafelineAPI/internal/app/safeLineApi"
	"fmt"
	"net/url"
)

type Host struct {
	HostName string `json:"HostName"`
	Port     string `json:"Port"`
}

func (host Host) String() string {
	if host.Port == "" {
		return host.HostName
	}
	return host.HostName + ":" + host.Port
}

func (host Host) Verify() bool {
	if host.HostName == "" {
		logger.Warning.Printf("No %shostname%s set: please check the %sSafeLine.Host.HostName%s parameter", logger.Cyan, logger.Reset, logger.Yellow, logger.Reset)
		return true
	}
	return false
}

func (host Host) VerifyCommand() bool {
	if host.HostName == "" {
		logger.Warning.Printf("No %shostname%s set: please check the %s-h%s command-line argument", logger.Cyan, logger.Reset, logger.Yellow, logger.Reset)
		return true
	}
	return false
}

func (host Host) Url() *safeLineApi.URL {
	var u *url.URL
	if host.Port == "" {
		u, _ = url.Parse(fmt.Sprintf("https://%s", host.HostName))
	} else {
		u, _ = url.Parse(fmt.Sprintf("https://%s:%s", host.HostName, host.Port))
	}
	return (*safeLineApi.URL)(u)
}
